Question: In java please! I provided code below. /** GeometricObject class */ public class GeometricObject { private String color; /** Construct a default geometric object */
In java please! I provided code below.
/** GeometricObject class */
public class GeometricObject { private String color; /** Construct a default geometric object */ public GeometricObject() { color = "white"; } /** Construct a geometric object with the specified color */ public GeometricObject(String color) { this.color = color; } /** Return color */ public String getColor() { return color; } /** Set a new color */ public void setColor(String color) { this.color = color; } public void print() { System.out.println("Geometric object with color = "+color); } /** Return a string representation of this object */ public String toString() { return " color: " + color; } }
------
/** Circle via Inheritance from GeometricObject */
public class Circle extends GeometricObject { private double radius; public Circle() { radius = 1.0; } public Circle(double radius) { this.radius = radius; } /** Return radius */ public double getRadius() { return radius; } /** Set a new radius */ public void setRadius(double radius) { this.radius = radius; } /** Return area */ public double getArea() { return radius * radius * Math.PI; } /** Return diameter */ public double getDiameter() { return 2 * radius; } /** Return perimeter */ public double getPerimeter() { return 2 * radius * Math.PI; } /* Print the circle info */ public void print() { System.out.println(" Circle with INHERITANCE : ......"); System.out.println(" The radius is "+radius); System.out.println("Area is "+getArea()); } }

1 Write a program that meets the following: 1. Define a class called ComparableCircle that will extends Circle and implement Comparable. 2. You should override the compareTo() method such that it will use the area of circle object for comparison. 3. Overide the tostring () method to print radius and area of circle. 4. Write a test method to create an array of size 5 of ComparableCircle objects. 5. Sort the array. 6. Print each element of the array by printing the string returned from the toString () method in ComparableCircle class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
