java programming question design a class comparablecircle
Get quality term paper help at Unemployedprofessor.net. Use our paper writing services to score better and meet your deadlines. It is simple and straightforward. Whatever paper you need—we will help you write it!
Order a Similar Paper Order a Different Paper
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 + “ncolor: ” + 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
— Prompts For Keyboard/Console/Standard Input —
Enter radius of second circle:
Inputs
— Keyboard/Console/Standard Input stdin —
17.2
Outputs
— Monitor/Console/Standard Output —
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Driver
Enter radius of first circle: 33.5
Enter radius of second circle: 17.2
1
SAMPLE RUN #2
— Prompts For Keyboard/Console/Standard Input —
Enter radius of second circle:
Inputs
— Keyboard/Console/Standard Input stdin —
22.34
Outputs
— Monitor/Console/Standard Output —
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Driver
Enter radius of first circle: 10.9
Enter radius of second circle: 22.34
-1
SAMPLE RUN #3
— Prompts For Keyboard/Console/Standard Input —
Enter radius of second circle:
Inputs
— Keyboard/Console/Standard Input stdin —
5.5
Outputs
— Monitor/Console/Standard Output —
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Driver
Enter radius of first circle:
5.5
Enter radius of second circle:
5.5
0
SAMPLE RUN #4
— Prompts For Keyboard/Console/Standard Input —
Enter radius of second circle:
Inputs
— Keyboard/Console/Standard Input stdin —
50.3
Outputs
— Monitor/Console/Standard Output —
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Driver
Enter radius of first circle:
100.22
Enter radius of second circle:
50.3
1
SAMPLE RUN #5
— Prompts For Keyboard/Console/Standard Input —
Enter radius of second circle:
Inputs
— Keyboard/Console/Standard Input stdin —
1.03
Outputs
— Monitor/Console/Standard Output —
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Driver
Enter radius of first circle:
1.02
Enter radius of second circle:
1.03
-1
SAMPLE RUN #6
— Prompts For Keyboard/Console/Standard Input —
Enter radius of second circle:
Inputs
— Keyboard/Console/Standard Input stdin —
10.0
Outputs
— Monitor/Console/Standard Output —
What The Console Looks Like In An Interactive Session:
(Note: this combines standard input with standard output )
>java Driver
Enter radius of first circle:
10.0
Enter radius of second circle:
10.0
0

Our affordable academic writing services save you time, which is your most valuable asset. Share your time with your loved ones as our Unemployedprofessor.net experts deliver unique, and custom-written paper for you.
Get a 15% discount on your order using the following coupon code SAVE15
Order a Similar Paper Order a Different Paper