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);}}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education