Question: Hi , would you be able to my code and see if it meet the specifications below, if not update if for me . Thank

Hi, would you be able to my code and see if it meet the specifications below, if not update if for me. Thank you.
The class have one member variable called radius of type double
The class have appropriate constructor.
The clas have an equals method. Define two Circle objects to be equal if they have the same radius (Circle one is less than Circle two if the radius of Circle one is less than the radius of Circle two. The two Circles are equal if they have the same radius. Circle one is larger than Circle two if its radius is larger).
The class should have a method called findArea (area = pr2).
The class have a method called findCircumference (circumference =2pr).
The class have a toString method. This method should construct a String containing the radius, area, and perimeter of the circle. For example Radius: 1 Area: 3.14159 Circumference: 6.28318.
The class implements the Comparable interface. Circle one is less than Circle two if the radius of Circle one is less than the radius of Circle two. The two Circles are equal if they have the same radius. Circle one is larger than Circle two if its radius is larger. If circle One.compareTo circle Two <>
import java.lang.Math;
public class Circle implements Comparable {
private double radius;
public Circle(double radius){
this.radius = radius;
}
public double findArea(){
return Math.PI * Math.pow(this.radius, 2);
}
public double findCircumference(){
return 2* Math.PI * this.radius;
}
@Override
public boolean equals(Object obj){
if (this == obj) return true;
if (obj == null || getClass()!= obj.getClass()) return false;
Circle circle =(Circle) obj;
return Double.compare(circle.radius, radius)==0;
}
@Override
public String toString(){
return "Radius: "+ this.radius +" Area: "+ this.findArea()+" Circumference: "+ this.findCircumference();
}
@Override
public int compareTo(Circle c){
return Double.compare(this.radius, c.radius);
}
}
#Test Class
a). It has an ArrayList that holds objects of type Circle.
b). It displays a menu that allows the user to:
Enter a Circle (the user only needs to enter the radius).
Print all Circles (print the toString for each Circle in the ArrayList).
c). If the user selects option 1, allow the user to input the radius of a circle. Place the circle in the ArrayList in order. You can do this by using loops and the CompareTo method. Do not use methods of ArrayList for this part. Use the compareTo method to insert elements into the array. For example addAt.
d) To adda a circle
Cases:
The ArrayList is empty
The new circle is less than the first circle, add it at the beginning.
The circle is greater than the last circle, add it at the end
The new circle belongs somewhere in the middle.
e). If the user selects option 2, loop through the ArrayList and print the toString for each member of the list.
import java.util.ArrayList;
import java.util.Scanner;
public class CircleTest {
private ArrayList circles = new ArrayList<>();
public void start(){
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("
1. Enter a Circle
2. Print all Circles
3. Quit");
choice = scanner.nextInt();
switch (choice){
case 1:
System.out.println("Enter the radius of the Circle:");
double radius = scanner.nextDouble();
Circle circle = new Circle(radius);
addCircle(circle);
break;
case 2:
printCircles();
break;
case 3:
System.out.println("Quitting...");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice !=3);
scanner.close();
}
private void addCircle(Circle circle){
if (circles.isEmpty()){
circles.add(circle);
} else if (circle.compareTo(circles.get(0))<0){
circles.add(0, circle);
} else if (circle.compareTo(circles.get(circles.size()-1))>0){
circles.add(circle);
} else {
for (int i =0; i < circles.size(); i++){
if (circle.compareTo(circles.get(i))<0){
circles.add(i, circle);
break;
}
}
}
}
private void printCircles(){
for (Circle circle : circles){
System.out.println(circle);
}
}
public static void main(String[] args){
CircleTest test = new CircleTest();
test.start();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!