Question
PLEASE ANSWER THE NELOW IN JAVA, THANK YOU! //GEOMTRIC CLASS package week03; public abstract class GeometricObject { private String color = white; private boolean filled;
PLEASE ANSWER THE NELOW IN JAVA, THANK YOU!
//GEOMTRIC CLASS
package week03;
public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated;
/** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); }
/** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; }
/** Return color */ public String getColor() { return color; }
/** Set a new color */ public void setColor(String color) { this.color = color; }
/** * Return filled. Since filled is boolean, the get method is named isFilled */ public boolean isFilled() { return filled; }
/** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; }
/** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }
/** Return a string representation of this object */ public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; }
/** Abstract method getArea */ public abstract double getArea();
/** Abstract method getPerimeter */ public abstract double getPerimeter(); }
================================================
//GEOMETRIC OBJECT TEST
package week03;
public class GeometricObjectTest { /** Main method */ public static void main(String[] args) { // Declare and initialize two geometric objects GeometricObject geoObject1 = new Circle(5); GeometricObject geoObject2 = new Rectangle(5, 3);
// Display circle displayGeometricObject(geoObject1);
// Display rectangle displayGeometricObject(geoObject2); System.out.println("The two objects have the same area? " + equalArea(geoObject1, geoObject2)); } /** A method for displaying a geometric object */ public static void displayGeometricObject(GeometricObject object) { System.out.println(); System.out.printf("The area is %.2f%n", object.getArea()); System.out.printf("The perimeter is %.2f%n", object.getPerimeter()); } /** A method for comparing the areas of two geometric objects */ public static boolean equalArea(GeometricObject object1, GeometricObject object2) { return object1.getArea() == object2.getArea(); } }
. Design and modify the GeometricObject class GeometricObject.java) to implement the Comparable interface. Make sure to use the GeometricObject.java file from sample codes. The modified GeometricObject class must implement the Comparable interface with the following features: Implement the compareTo method. This method must compare the area of this object to the area of the given object. o If this objects area is greater than the given objects area, it returns 1. o If this objects area is smaller than the given object's area, it returns -1. o If this object's area is equal to the given objects area, it returns 0. Define a static method called max for finding the larger of two given GeometricObject instances. o public static GeometricObject max(GeometricObject ol, GeometricObject 02) o You need to call the compareTo method in the max method. o If both the GeometricObject instances are equal, it returns the first given GeometricObject instance. O Write a testing Java application (GeometricObjectTest.java) such that: Creates two Circle objects called circlel (radius =5) and circle2 (radius =4) Creates two Rectangle objects called rectanglel (width = 5 and height = 4) and rectangle2 (width= 4 and height = 5) Use the max method to find the larger of two circles and display its radius. Use the max method to find the larger of two rectangles and display its width and height Use the max method to find the larger of (circlel, rectanglel) and display its fields (either radius or width/height). Note: You MUST NOT change the Circle and Rectangle class in the sample codesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started