Question

Problem: Develop the ‘Shape’ application such that: · ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit from the...

Problem: 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

ShapeTest.java

public class ShapeTest
{

public static void main(String args[])
{
Square s =new Square();
s.draw();
s.erase();
s.move();
Circle c=new Circle();
c.draw();
c.erase();
c.move();

Traingle t=new Traingle();
t.draw();
t.erase();
t.move();
  
}}

Shape.java
class Shape{
protected String name;
protected String phoneNumber;
Shape()
{
System.out.println("shape class constructor");
}
public void draw()
{
System.out.println("shape draw mwthod");
}
public void move()
{
System.out.println("shape move mwthod");
}
public void erase()
{
System.out.println("shape erase mwthod");
}
  
}

Rectangle.java
class Rectangle extends Shape
{
Rectangle()
{
System.out.println("Rectangle class constructor");
}
public void draw()
{
System.out.println("rectangle draw mwthod");
}
public void move()
{
System.out.println("rectangle move mwthod");
}
public void erase()
{
System.out.println("rectangle erase mwthod");
}
  
}

Traingle.java
class Traingle extends Shape
{
Traingle()
{
System.out.println("Traingle class constructor");
}
public void draw()
{
System.out.println("traingle draw mwthod");
}
public void move()
{
System.out.println("traingle move mwthod");
}
public void erase()
{
System.out.println("traingle erase mwthod");
}
  
}

Ellipse.java
class Ellipse extends Shape
{
Ellipse()
{
System.out.println("Ellipse class constructor");
}
public void draw()
{
System.out.println("ellipse draw mwthod");
}
public void move()
{
System.out.println("ellipse move mwthod");
}
public void erase()
{
System.out.println("ellipse erase mwthod");
}
  
}

Square.java

class Square extends Rectangle
{
Square()
{
System.out.println("Square class constructor");
}
public void draw()
{
System.out.println("square draw mwthod");
}
public void move()
{
System.out.println("square move mwthod");
}
public void erase()
{
System.out.println("square erase mwthod");
}
  
}

Circle.java
class Circle extends Ellipse
{
Circle()
{
System.out.println("Circle class constructor");
}
public void draw()
{
System.out.println("circle draw mwthod");
}
public void move()
{
System.out.println("circle move mwthod");
}
public void erase()
{
System.out.println("circle erase mwthod");
}
  
}

Add a comment
Know the answer?
Add Answer to:
Problem: Develop the ‘Shape’ application such that: · ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT