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

I have a Polymorhpism Project that builds upon an Inheritance Project. I have ad

ID: 3572264 • Letter: I

Question

I have a Polymorhpism Project that builds upon an Inheritance Project. I have added the main file of my Inheritance project below (it's the only file that needs to be changed) and I was hoping I could get some help with these requirements:

Problem: Develop the ‘Shape’ application such that:
Implement an array of objects of various types (all SIX 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 six shape classes from Lab-7 should remain unchanged.

Inheritance Project (main file):

import java.util.*;
import java.lang.*;
import java.io.*;

public class Inheritance {

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();

s.draw();
s.move();
s.erase();

r.draw();
r.move();
r.erase();

e.draw();
e.move();
e.erase();

t.draw();
t.move();
t.erase();

sq.draw();
sq.move();
sq.erase();

c.draw();
c.move();
c.erase();
}
}

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");
}
}

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");
}
}

Shape 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");
}
}

Square class:

lass 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");
}
}

Explanation / Answer

HI, PLEASE find my implementation. I have changed the required test class.

public class Inheritance {

   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

*/