Question: My Java program is has errors can I please get help on where I made a mistake. I made 4 classes and the 5th class

My Java program is has errors can I please get help on where I made a mistake. I made 4 classes and the 5th class is to test the Shapes.

Shape.java (class)

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

public abstract class Shape { //Variables int X; int Y; // Constructors Shape() { } Shape (int X, int Y) { this.X = X; this.Y = Y; } // Set X public void setX(int X) { this.X = X; } // Get X and return it public int getX() { return X; } // Set Y public void setY(int Y) { this.Y =Y; } // Get Y and return it public int getY() { return Y; } //Gets Name, Area, and Perimeter abstract String getName(); abstract double getArea(); abstract double getPerimeter(); }

___________________________

GeometricObject.java (class)

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

import java.util.Date;

public abstract class GeometricObject extends Shape implement Comparable{ // Variables String color; boolean filled; Date dateCreated; } // Constructors GeometricObject() { }

GeometricObject (String color, boolean filled) { this.color = color; this.filled = filled; }

// Gets the color and retunr it public String getColor() { return color; }

// Sets the color public void setColor (String color) { this.color = color; }

//Sets the filled public void setFilled(boolean filled) { this.filled = filled; }

// Gets the DateCreated and return it public Date getDateCreated() { return dateCreated; }

public String toString() {

}

@Override public int compareTo(Object obj){ GeometricObject o = (GeometricObject)obj; return 0;

// Method max public static GeometricObject max(GeometricObject o1, GeometricObject o2){ if (01.compareTo(o2)>0) return o1; else return o2; } }

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

Rectangle.java (class)

_____________________________

public class Rectangle extends GeometricObject { // Variables double width; double height; // Constructors Rectangle(double width, double height, String color, boolean filled) { super(color,filled); this.width = width; this.height = height; }

Rectangle(int i, int i0) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }

Rectangle() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } // Get width and return it public double getWidth() { return width; } // Set width public void setWidth(double width) { this.width = width; } // Get height and return it public double getHeight() { return height; } // Set height public void setHeight(double height) { this.height = height; } // Get Name, Area, and Perimeter and return them String getName() { return "Rectangle"; } double getArea() { double Area = width*height; return Area; } double getPerimeter() { double Perimeter= width*2 + height*2; return Perimeter; } public int compareTo(Object obj) { GeometricObject o=(GeometricObject)obj; return 0; } }

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

Circle.java (class)

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

public class Circle extends GeometricObject { double radius; private double Diameter; //Constructors Circle() { } Circle(double radius) { this.radius = radius; } public Circle(double radius, String color, boolean filled) { super(color,filled); this.radius = radius; } // Get radius and return it public double getRadius() { return radius; } // Set radius public void setRadius(double radius) { this.radius = radius; } // Get Name and return it String getName() { return "Circle"; } // Calculate then get Area and return it double getArea() { double Area = radius * radius * Math.PI; return Area; } //Get Diameter and return it double getDiameter() { double Diameter = radius * 2; return Diameter; } public void setDiameter(double Diameter) { this.Diameter = Diameter; } // Calculate the get Perimeter and diameter double getPerimeter() { double Perimeter = Diameter * 2; return Perimeter; } // Method Max public int compareTo(Object obj) { GeometricObject o=(GeometricObject)obj; return 0; } }

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

ShapeTest.java (class) I cannot change the ShapeTest class

-------------------------------------------------------------------------- import java.util.ArrayList;

public class ShapeTest {

public static void main(String[] args) { ArrayList shapes=new ArrayList<>(); Circle circle1=new Circle(3.0); Circle circle2=new Circle(6.0,"Red",true); Rectangle rect1 = new Rectangle(71,96); Rectangle rect2 = new Rectangle(); shapes.add(circle1); shapes.add(circle2); shapes.add(rect1); shapes.add(rect2);

//call method to print all for(Shape currentShape:shapes){ System.outprintf("%s: %s", currentShape.getName(), currentShape); if(currentShape instanceof GeometricObject){ //(Circle) currentShape; System.out.printf("%s's area is %.2f ", currentShape.getName(),currentShape.getArea()); // print the perimeter System.out.printf("%s's perimeter is %.2f ", currentShape.getName(),currentShape.getPerimeter()); //Print the line System.out.println("---------------------------"); }//end if }//end for //Display the max circle Circle circle=(Circle) GeometricObject.max(circle1, circle2); System.out.println("The max circle radius: "+circle.getRadius()); System.out.println("---------------------------"); //Display the max rectangle Rectangle rectangle=(Rectangle) GeometricObject.max(rect1, rect2); System.out.println("The max rectangle's width is " +rectangle.getWidth()+"and height"+rectangle.getHeight()); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!