Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop the ‘Shape’ application such that: -‘Rectangle’, ‘Ellipse’, and ‘Triangl

ID: 3691449 • Letter: D

Question

Develop the ‘Shape’ application such that:

    -‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit from the ‘Shape’ class.

-Develop the ‘Square’ and ‘Circle’ class where ‘Square’ inherits from ‘Rectangle’ and ‘Circle’ inherits from ‘Ellipse’. ‘Triangle’ has no derived class.

-For each class, implement the overridden methods ‘draw’, ‘move’, and ‘erase’. Each method should only have an output statement such as "Rectangle – draw method" that will be displayed when the method is invoked.

-Implement the default constructors for each class with a corresponding message to be displayed when invoked. No initializations are required; that is, the output message will be the only executable statement in the constructors.

-Do not implement any other methods for these classes ( i.e., ‘toString’, ‘equals’, getters and setters ).

-Implement a ‘ShapeTest’ class which will instantiate an object of each class.

-Exercise each of the ‘draw’, ‘move’, and ‘erase’ methods of each class

-Remember to make sure that there is only a single class per file.

------------------------------------------------------------------------------------------

REQUIREMENTS

    EXACTLY SEVEN files; one for each class

FOUR methods per class; the default constructor, the draw, move, and erase methods.

ONE SINGLE statement per shape class method; an output statement.

--------------------

****IN JAVA****

****PLEASE INCLUDE COMMENTS IN CODE*****

Explanation / Answer

Shape.java

package org.students;

public class Shape {
   //Default constructor
   public Shape() {
       System.out.println(":: Shape Object is created ::");
   }
   //draw method
   public void draw()
   {
   System.out.println("Shape - draw method");  
   }
   //Move method
   public void move()
   {
       System.out.println("Shape - move method");      
   }
   //erase method
   public void erase()
   {
       System.out.println("Shape - move method");
   }
}

__________________________________________________________________________________________

Rectangle.java

package org.students;

public class Rectangle extends Shape
{
   //Default constructor
public Rectangle()
{
   System.out.println(":: Rectangle Object is created ::");
}
//Overriding the draw method
@Override
public void draw()
   {
   System.out.println("Rectangle - draw method");  
   }
//Overriding the move method
@Override
   public void move()
   {
       System.out.println("Rectangle - move method");      
   }
//Overriding the erase method
@Override
   public void erase()
   {
       System.out.println("Rectangle - move method");
   }
}

__________________________________________________________________________________________

Ellipse.java

package org.students;

public class Ellipse extends Shape
{
   //Default constructor
public Ellipse()
{
   System.out.println(":: Ellipse Object is created ::");
}
//Overriding the draw method
@Override
public void draw()
   {
   System.out.println("Ellipse - draw method");  
   }
//Overriding the move method
@Override
   public void move()
   {
       System.out.println("Ellipse - move method");      
   }
//Overriding the erase method
@Override
   public void erase()
   {
       System.out.println("Ellipse - move method");
   }
}

___________________________________________________________________________________________

Triangle.java

package org.students;

public class Triangle extends Shape {
   //Default constructor
public Triangle()
{
   System.out.println(":: Triangle Object is created ::");
}
//Overriding the draw method
@Override
public void draw()
   {
   System.out.println("Triangle - draw method");  
   }
//Overriding the move method
@Override
   public void move()
   {
       System.out.println("Triangle - move method");      
   }
//Overriding the erase method
@Override
   public void erase()
   {
       System.out.println("Triangle - move method");
   }
}

__________________________________________________________________________________________

Square.java

package org.students;

public class Square extends Rectangle
{
   //Default constructor
public Square()
{
   System.out.println(":: Square Object is created ::");
}
//Overriding the draw method
@Override
public void draw()
   {
   System.out.println("Square - draw method");  
   }
//Overriding the move method
@Override
   public void move()
   {
       System.out.println("Square - move method");      
   }
//Overriding the erase method
@Override
   public void erase()
   {
       System.out.println("Square - move method");
   }
}

________________________________________________________________________________________

Circle.java

package org.students;

public class Circle extends Ellipse {
   //Default constructor
public Circle()
{
   System.out.println(":: Circle Object is created ::");
}
//Overriding the draw method
@Override
public void draw()
   {
   System.out.println("Circle - draw method");  
   }
//Overriding the move method
@Override
   public void move()
   {
       System.out.println("Circle - move method");      
   }
//Overriding the erase method
@Override
   public void erase()
   {
       System.out.println("Circle - move method");
   }
}

__________________________________________________________________________________________

ShapeTest.java

package org.students;

public class ShapeTest {

   public static void main(String[] args) {
       //Creating the Shape class Object
       Shape s=new Shape();
       s.draw();
       s.erase();
       s.move();
       //Creating the Rectangle class Object
       Rectangle r=new Rectangle();
       r.draw();
       r.erase();
       r.move();
       //Creating the Ellipse class Object
       Ellipse e=new Ellipse();
       e.draw();
       e.erase();
       e.move();
       //Creating the Triangle class Object
       Triangle t=new Triangle();
       t.draw();
       t.erase();
       t.move();
       //Creating the Square class Object
       Square sq=new Square();
       sq.draw();
       sq.erase();
       sq.move();
       //Creating the Circle class Object
       Circle c=new Circle();
       c.draw();
       c.erase();
       c.move();
      
   }

}

_________________________________________________________________________________________

output:

:: Shape Object is created ::
Shape - draw method
Shape - move method
Shape - move method
:: Shape Object is created ::
:: Rectangle Object is created ::
Rectangle - draw method
Rectangle - move method
Rectangle - move method
:: Shape Object is created ::
:: Ellipse Object is created ::
Ellipse - draw method
Ellipse - move method
Ellipse - move method
:: Shape Object is created ::
:: Triangle Object is created ::
Triangle - draw method
Triangle - move method
Triangle - move method
:: Shape Object is created ::
:: Rectangle Object is created ::
:: Square Object is created ::
Square - draw method
Square - move method
Square - move method
:: Shape Object is created ::
:: Ellipse Object is created ::
:: Circle Object is created ::
Circle - draw method
Circle - move method
Circle - move method

_________________________________________________________________________________________