Develop the Shape application such that Implement an array o

Develop the ‘Shape’ application such that:

Implement an array of objects of various types (all five classes), in any order.

In some type of a looping structure, demonstrate polymorphism by calling all three of the methods, draw, move, and erase. That is, within the curly braces, there will be only three method calls.

Verify that the output messages come from all three methods, from all seven classes.

The only class that you should have to develop for this class will be the test application.

The seven classes from last week should remain unchange.

Below is my Code For Each Class. I really really need help with Above question.

class Shape
{

public Shape()
{
System.out.println(\"Shape - default constructor\");
}

public void draw()
{
System.out.println(\"Shape draw method\");
}

public void move()
{
System.out.println(\"Shape move method\");
}

public void erase()
{
System.out.println(\"Shape erase method\");
}
}

class Rectangle extends Shape
{
public Rectangle()
{
System.out.println(\"Rectangle - default constructor\");
}

public void draw()
{
System.out.println(\"Rectangle draw method\");
}

public void move()
{
System.out.println(\"Rectangle move method\");
}

public void erase()
{
System.out.println(\"Rectangle erase method\");
}
}

class Ellipse extends Shape
{
public Ellipse()
{
System.out.println(\"Ellipse - default constructor\");
}

public void draw()
{
System.out.println(\"Ellipse draw method\");
}

public void move()
{
System.out.println(\"Ellipse move method\");
}

public void erase()
{
System.out.println(\"Ellipse erase method\");
}
}

class Triangle extends Shape
{
public Triangle()
{
System.out.println(\"Triangle - default constructor\");
}

public void draw()
{
System.out.println(\"Triangle draw method\");
}

public void move()
{
System.out.println(\"Triangle move method\");
}

public void erase()
{
System.out.println(\"Triangle erase method\");
}
}

class Square extends Rectangle
{
public Square()
{
System.out.println(\"Square - default constructor\");
}

@Override
public void draw()
{
System.out.println(\"Square draw method\");
}

@Override
public void move()
{
System.out.println(\"Square move method\");
}

@Override
public void erase()
{
System.out.println(\"Square erase method\");
}
}

class Circle extends Ellipse
{
public Circle()
{
System.out.println(\"Circle - default constructor\");
}

@Override
public void draw()
{
System.out.println(\"Circle draw method\");
}

@Override
public void move()
{
System.out.println(\"Circle move method\");
}

@Override
public void erase()
{
System.out.println(\"Circle erase method\");
}
}

public class ShapeTest
{
public static void main(String[] args)
{
Shape s1 = new Shape();
s1.draw();
s1.erase();
s1.move();
Rectangle r1 = new Rectangle();
r1.draw();
r1.erase();
r1.move();
Ellipse e1 = new Ellipse();
e1.draw();
e1.erase();
e1.move();
Triangle t1 = new Triangle();
t1.draw();
t1.erase();
t1.move();
Square sq1 = new Square();
sq1.draw();
sq1.erase();
sq1.move();
Circle c1 = new Circle();
c1.draw();
c1.erase();
c1.move();

}

}

Solution

Note:

The output is correct .When we are creating the subclass object ,before calling the sub class constructor,super class constructor will be created.That\'s the reason the output is like this, when we are creating an array of objects.

______________________

Shape.java

public class Shape {
   public Shape()
   {
   System.out.println(\"Shape - default constructor\");
   }
   public void draw()
   {
   System.out.println(\"Shape draw method\");
   }
   public void move()
   {
   System.out.println(\"Shape move method\");
   }
   public void erase()
   {
   System.out.println(\"Shape erase method\");
   }
}

_________________

Rectangle.java

public class Rectangle extends Shape {
   public Rectangle()
   {
   System.out.println(\"Rectangle - default constructor\");
   }
   public void draw()
   {
   System.out.println(\"Rectangle draw method\");
   }
   public void move()
   {
   System.out.println(\"Rectangle move method\");
   }
   public void erase()
   {
   System.out.println(\"Rectangle erase method\");
   }
}

_______________________

Ellipse.java

public class Ellipse extends Shape {
   public Ellipse()
   {
   System.out.println(\"Ellipse - default constructor\");
   }
   public void draw()
   {
   System.out.println(\"Ellipse draw method\");
   }
   public void move()
   {
   System.out.println(\"Ellipse move method\");
   }
   public void erase()
   {
   System.out.println(\"Ellipse erase method\");
   }
}

________________________

Triangle.java

public class Triangle extends Shape {
   public Triangle()
   {
   System.out.println(\"Triangle - default constructor\");
   }
   public void draw()
   {
   System.out.println(\"Triangle draw method\");
   }
   public void move()
   {
   System.out.println(\"Triangle move method\");
   }
   public void erase()
   {
   System.out.println(\"Triangle erase method\");
   }
}

______________________

Square.java

public class Square extends Rectangle {
   public Square()
   {
   System.out.println(\"Square - default constructor\");
   }
   @Override
   public void draw()
   {
   System.out.println(\"Square draw method\");
   }
   @Override
   public void move()
   {
   System.out.println(\"Square move method\");
   }
   @Override
   public void erase()
   {
   System.out.println(\"Square erase method\");
   }
}

_____________________

Circle.java

public class Circle extends Ellipse {
   public Circle()
   {
   System.out.println(\"Circle - default constructor\");
   }
   @Override
   public void draw()
   {
   System.out.println(\"Circle draw method\");
   }
   @Override
   public void move()
   {
   System.out.println(\"Circle move method\");
   }
   @Override
   public void erase()
   {
   System.out.println(\"Circle erase method\");
   }
}

_______________________

Output:

_______ Creating An Array Of Objects ______
Shape - default constructor
Shape - default constructor
Rectangle - default constructor
Shape - default constructor
Ellipse - default constructor
Shape - default constructor
Triangle - default constructor
Shape - default constructor
Rectangle - default constructor
Square - default constructor
Shape - default constructor
Ellipse - default constructor
Circle - default constructor
____Calling the methods on the Shape Objects_____
Shape draw method
Shape erase method
Shape move method
________________
Rectangle draw method
Rectangle erase method
Rectangle move method
________________
Ellipse draw method
Ellipse erase method
Ellipse move method
________________
Triangle draw method
Triangle erase method
Triangle move method
________________
Square draw method
Square erase method
Square move method
________________
Circle draw method
Circle erase method
Circle move method
________________

______Thank You

Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,
Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,
Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,
Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,
Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,
Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,
Develop the ‘Shape’ application such that: Implement an array of objects of various types (all five classes), in any order. In some type of a looping structure,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site