Java programming question design a class ComparableCircle

Nov 16th, 2014
FratBro23
Category:
Programming
Price: $115 USD

Question description

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 first circle:
Enter radius of second circle:

Inputs

--- Keyboard/Console/Standard Input stdin ---

33.5 
17.2 

Outputs 

--- Monitor/Console/Standard Output  ---

Enter radius of first circle:Enter radius of second circle:1

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 first circle:
Enter radius of second circle:

Inputs

--- Keyboard/Console/Standard Input stdin ---

10.9 
22.34 

Outputs 

--- Monitor/Console/Standard Output  ---

Enter radius of first circle:Enter radius of second circle:-1

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 first circle:
Enter radius of second circle:

Inputs

--- Keyboard/Console/Standard Input stdin ---

5.5 
5.5 

Outputs 

--- Monitor/Console/Standard Output  ---

Enter radius of first circle:Enter radius of second circle:0

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 first circle:
Enter radius of second circle:

Inputs

--- Keyboard/Console/Standard Input stdin ---

100.22 
50.3 

Outputs 

--- Monitor/Console/Standard Output  ---

Enter radius of first circle:Enter radius of second circle:1

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 first circle:
Enter radius of second circle:

Inputs

--- Keyboard/Console/Standard Input stdin ---

1.02 
1.03 

Outputs 

--- Monitor/Console/Standard Output  ---

Enter radius of first circle:Enter radius of second circle:-1

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 first circle:
Enter radius of second circle:

Inputs

--- Keyboard/Console/Standard Input stdin ---

10.0 
10.0 

Outputs 

--- Monitor/Console/Standard Output  ---

Enter radius of first circle:Enter radius of second circle:0

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


Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Purdue University
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
ddg82
Dec 8th, 2016
" Thanks, good work "
tinytim47
Nov 25th, 2016
" Wow this is really good.... didn't expect it. Sweet!!!! "
kenmwao2
Nov 24th, 2016
" Solid work, thanks. "
jestin7
Nov 16th, 2016
" This tutor is great! "
lilmoe415
Nov 2nd, 2016
" Thank you, Thank you, for top quality work, this is your guy!! "
dontuwannaknow
Oct 11th, 2016
" Excellent work as always thanks so much "
thargrow
Oct 2nd, 2016
" Very Satisfied. "
SjSurvivor143
Sep 27th, 2016
" Thanks for the help. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1826 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors