Uising the code below. Write a test class called CircleTest that implement below specification: a). The class 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). Quit. 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 add 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.lang.Math;public class Circle implements Comparable<Circle> {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;}@Overridepublic 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;}@Overridepublic String toString() {return "Radius: " + this.radius + " Area: " + this.findArea() + " Circumference: " + this.findCircumference();}@Overridepublic int compareTo(Circle c) {return Double.compare(this.radius, c.radius);}}

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

Uising the code below. Write a test class called CircleTest that implement below specification:

a). The class has an ArrayList that holds objects of type Circle.

b). It displays a menu that allows the user to:

  1. Enter a Circle (the user only needs to enter the radius).
  2. Print all Circles (print the toString for each Circle in the ArrayList).
  3. Quit.

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 add 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.lang.Math;

public class Circle implements Comparable<Circle> {
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);
}
}

AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT