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 pr
The class have a method called findCircumference circumference pr
The class have a toString method. This method should construct a String containing the radius, area, and perimeter of the circle. For example Radius: Area: Circumference:
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 Circledouble radius
this.radius radius;
public double findArea
return Math.PI Math.powthisradius, ;
public double findCircumference
return Math.PI this.radius;
@Override
public boolean equalsObject obj
if this obj return true;
if obj null getClass obj.getClass return false;
Circle circle Circle obj;
return Double.comparecircleradius, radius;
@Override
public String toString
return "Radius: this.radius Area: this.findArea Circumference: this.findCircumference;
@Override
public int compareToCircle c
return Double.comparethisradius, cradius;
#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 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 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 ScannerSystemin;
int choice;
do
System.out.println
Enter a Circle
Print all Circles
Quit";
choice scanner.nextInt;
switch choice
case :
System.out.printlnEnter the radius of the Circle:";
double radius scanner.nextDouble;
Circle circle new Circleradius;
addCirclecircle;
break;
case :
printCircles;
break;
case :
System.out.printlnQuitting;
break;
default:
System.out.printlnInvalid choice. Please try again.";
while choice ;
scanner.close;
private void addCircleCircle circle
if circlesisEmpty
circles.addcircle;
else if circlecompareTocirclesget
circles.add circle;
else if circlecompareTocirclesgetcirclessize
circles.addcircle;
else
for int i ; i circles.size; i
if circlecompareTocirclesgeti
circles.addi circle;
break;
private void printCircles
for Circle circle : circles
System.out.printlncircle;
public static void mainString 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
