Question
Modify the GeometricObject1.java abstract class (code given below) to contain: the abstract findArea() and findPerimeter() methods; abstract class GeometricObject1 { protected String color; protected double
Modify the GeometricObject1.java abstract class (code given below) to contain: the abstract findArea() and findPerimeter() methods;
abstract class GeometricObject1 { protected String color; protected double weight;
// Default construct
protected GeometricObject1() { color = "white"; weight = 1.0;
}
// Construct a geometric object
protected GeometricObject1(String color, double weight) {this.color = color; this.weight = weight;
}
// Getter method for color
public String getColor() { return color;
}
// Setter method for color
public void setColor(String color) { this.color = color;
}
// Getter method for weight
public double getWeight() { return weight;
}
// Setter method for weight
public void setWeight(double weight) { this.weight = weight;
}
//Write code here for Abstract method for area
//Write code here Abstract method for perimeter
}
Then create Circle1.java class that extends the abstract GeometricObject1.java class (from above) and implements the Comparable interface. In Circle1.java you must:
implement the compareTo() method from the Comparable interface
define a public static Circle1 max(Comparable o1, Comparable o2) method for finding the
larger of two circles, using the compareTo() method, and return the larger of the two circles
override findPerimeter() and findArea() from the GeometricObject1 class
override equals() and toString() from the Object class
Use the template code below for creating the Circle1 class.
class Circle1 extends GeometricObject1 implements Comparable{protected double radius;
// Default constructor
public Circle1() { this(1.0, "white", 1.0);
}
// Construct circle with specified radius
public Circle1(double radius) { super("white", 1.0); this.radius = radius;
}
// Construct a circle with specified radius, weight, and color
public Circle1(double radius, String color, double weight) {super(color, weight); this.radius = radius;
}
// Getter method for radius
public double getRadius() { return radius;
}
// Setter method for radius
public void setRadius(double radius) { this.radius = radius;
}
// Implement the findArea method defined in GeometricObject
public double findArea() { // Write your code here
}
// Implement the findPerimeter method defined in GeometricObject
public double findPerimeter() { // Write your code here
}
// Override the equals() method defined in the Object class
public boolean equals(Circle1 circle) { // Write your code here }
// Override the toString() method defined in the Object class
public String toString() { // Write your code here
}
// Implement the compareTo method defined in Comparable
public int compareTo(Object o) {
// Write your code here
public static Circle1 max(Comparable o1, Comparable o2) {// Write your code here
} }
Then create the TestCircle1.java using the template code below for testing your Circle1.java class.
public class TestCircle1 { // Main method public static void main(String[] args) {
// Create two comparable circles
Circle1 circle1 = new Circle1(5); Circle1 circle2 = new Circle1(4);
// Display the max circle
Circle1 circle = Circle1.max(circle1, circle2); System.out.println("The max circle's radius is " + circle.getRadius()); System.out.println(circle); System.out.println(circle.equals(new Circle1(5)));
} }
Step 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