Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Java CODE DOWN BELOW _________________________________________________________ public class exam4p2 { // Main method public static void main(String[] args) { // Create two comparable circles Circle1
Using JavaCODE DOWN BELOW
_________________________________________________________
public class exam4p2 { // 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) GeometricObject1.max(circle1, circle2); System.out.println("The max circle's radius is " + circle.getRadius()); System.out.println(circle); } } abstract class GeometricObject1 //You complete this part { 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) { //You complete this part } // Getter method for color public String getColor() { return color; } public void setColor(String color) { //You complete this part } // Getter method for weight public double getWeight() { return weight; } // Setter method for weight public void setWeight(double weight) { //You complete this part } // Abstract method public abstract double getArea(); // Abstract method public abstract double getPerimeter(); public int compareTo //You complete this line { //You complete this part } public static GeometricObject1 max(GeometricObject1 o1, GeometricObject1 o2) { //You complete this part } } // Circle.java: The circle class that extends GeometricObject class Circle1 extends GeometricObject1 { protected double radius; // Default constructor public Circle1() { this(1.0, "white", 1.0); } // Construct circle with specified radius public Circle1(double radius) { //You complete this part } // Construct a circle with specified radius, weight, and color public Circle1(double radius, String color, double weight) { //You complete this part } // 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 getArea() { return radius * radius * Math.PI; } // Implement the findPerimeter method defined in GeometricObject public double getPerimeter() { return 2 * radius * Math.PI; } // Override the equals() method defined in the Object class public boolean equals(Circle1 circle) { return this.radius == circle.getRadius(); } @Override public String toString() { return "[Circle] radius = " + radius; } @Override public int compareTo(GeometricObject1 o) { if (getRadius() > ((Circle1) o).getRadius()) //You complete the rest } }III Problem 2: *13.5 (Enable GeometricObject comparable) Modify the GeometricObject class to implement the Comparable interface, and define a static max method in the GeometricObject class for finding the larger of two GeometricObject objects. Implement the new GeometricObject class. Write a test program that uses the max method to find the larger of two circles and the larger of two rectangles. Instructions: Given the following "main" method, complete the "exam4p2.java" so that the following output will be produced: 1. The "main" program: public class exam4p2 // Main method public static void main(Stringl args) // Create two comparable circles Circle1 circle1 new Circle1(5); Circle1 circle2- new Circle1(4); // Display the max circle Circle1 circle (Circle1) GeometricObject1.max(circle1,circle2); System.out.println("The max circle's radius is " +circle.getRadius() System.out.println(circle); Circle1) Geometricobject1.max(circle1, circle2); 2. The output of the complete program: The max circle's radius is 5.0 [Circle] radius = 5.0
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