Question: Define a class named ComparableCircle that extends Circle and implements Comparable. The Circle class extends the abstract class Geometric Object, both of which are defined
Define a class named ComparableCircle that extends Circle and implements Comparable. The Circle class extends the abstract class Geometric Object, both of which are defined below: //---------------GEOMETRIC OBJECT----------------- 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; } @Override 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(); } //-----------------------CIRCLE----------------------- class Circle extends GeometricObject { private double radius; public Circle() { } 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; } @Override /** Return area */ public double getArea() { return radius * radius * Math.PI; } /** Return diameter */ public double getDiameter() { return 2 * radius; } @Override /** Return perimeter */ public double getPerimeter() { return 2 * radius * Math.PI; } /* Print the circle info */ public void printCircle() { System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius); } } Implement the compareTo method in the ComparableCircle class, comparing the circles on the basis of area. If the original circle has a larger area, the compareTo function should return 1. If the original circle has a smaller area, the function should return -1, and if the two circles have the same area, the function should return 0. Test your ComparableCircle class in a Driver class that asks the user to input the radii of two circles. Your program should then print the result of the first circle's compareTo method (using the second circle as an argument).
SAMPLE RUN #1: java Driver
Interactive Session Standard Input Standard Error (empty) Standard Output Hide Invisibles Highlight: None Standard Input Only Prompts Only Standard Output w/o Prompts Full Standard Output All Show Highlighted Only Enterradiusoffirstcircle:33.5? Enterradiusofsecondcircle:17.2? 1?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
