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

Problem: Develop the \'Shape\' application such that: * \'Rectangle\', \'Ellispe

ID: 3824809 • Letter: P

Question

Problem: Develop the 'Shape' application such that:

* 'Rectangle', 'Ellispe', 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 onstructors 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.

Explanation / Answer

Hi, Please find my implementation.

please let me know in case of any issue.

//Shape class:

class Shape{

public Shape(){

System.out.println("Shape class - 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");

}

}

//Ellipse class:

class Ellipse extends Shape{

public Ellipse(){

System.out.println("Ellipse class - constructor");

}

  

@Override

public void draw() {

System.out.println("Ellipse - draw method");

}

  

@Override

public void move() {

System.out.println("Ellipse - move method");

}

  

@Override

public void erase() {

System.out.println("Ellipse - erase method");

}

}

//Rectangle class:

class Rectangle extends Shape{

public Rectangle(){

System.out.println("Rectangle class - constructor");

}

  

@Override

public void draw() {

System.out.println("Rectangle - draw method");

}

  

@Override

public void move() {

System.out.println("Rectangle - move method");

}

  

@Override

public void erase() {

System.out.println("Rectangle - erase method");

}

}

//Circle Class:

class Circle extends Ellipse{

public Circle(){

System.out.println("Circle class - 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");

}

}

//Square class:

class Square extends Rectangle{

public Square(){

System.out.println("Square class - 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");

}

}

//Triangle class:

class Triangle extends Shape{

public Triangle(){

System.out.println("Triangle class - constructor");

}

  

@Override

public void draw() {

System.out.println("Triangle - draw method");

}

  

@Override

public void move() {

System.out.println("Triangle - move method");

}

  

@Override

public void erase() {

System.out.println("Triangle - erase method");

}

}

public class ShapeTest {

   public static void main(String args[]) {

       Shape s = new Shape();

       Rectangle r = new Rectangle();

       Ellipse e = new Ellipse();

       Triangle t = new Triangle();

       Square sq = new Square();

       Circle c = new Circle();

      

       Shape[] shapes = {sq, c, s, e, r, t};

      

       for(Shape shape : shapes){

           shape.draw();

           shape.move();

           shape.erase();

       }

      

   }

}

/*

Sample Run:

Shape class - constructor

Shape class - constructor

Rectangle class - constructor

Shape class - constructor

Ellipse class - constructor

Shape class - constructor

Triangle class - constructor

Shape class - constructor

Rectangle class - constructor

Square class - constructor

Shape class - constructor

Ellipse class - constructor

Circle class - constructor

Square - draw method

Square - move method

Square - erase method

Circle - draw method

Circle - move method

Circle - erase method

Shape - draw method

Shape - move method

Shape - erase method

Ellipse - draw method

Ellipse - move method

Ellipse - erase method

Rectangle - draw method

Rectangle - move method

Rectangle - erase method

Triangle - draw method

Triangle - move method

Triangle - erase method

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote