Question: I need help on Java ArrayList. I got ArrayList is a private message This is the question Write a Circle class that has the following
I need help on Java ArrayList. I got ArrayList is a private message
This is the question
Write a Circle class that has the following fields: radius (double data type) PI (a final double initialized with the value 3.14159
The class should have the following methods: Constructor: Accepts the radius of the circle as an argument Constructor: A no-arg constructor that sets the radius field to 0.0 setRadius: A mutator method for the radius field getRadius: An accessor method for the radius field getArea: Returns the area of the circle, which is calculated as: area = PI * radius * radius getDiameter: Returns the diameter of the circle, which is calculated as: diameter = radius * 2 getCircumference: Returns the circumference of the circle, which is calculated as: circumference = 2 * PI * radius
Note: Review avoiding stale data in Chapter 6 before creating the calculation methods.
Write a program that creates Circle objects. The program should ask the user for the circle's radius. Validate the input. Do not accept a negative number for the radius. Store your objects in a container that will automatically expand as objects are added. The program should continue allowing the user to input until the user indicates to stop.
Display the circle's area, diameter, and circumference.
-------------------------------------------------------------------------------------------------------------------
here is my code
2 3 4 public class Circle 5 { 6 private double radius; 7 private final double PI=3.14159; 8 9 public Circle() 10 { 11 radius=0.0; 12 } 13 public Circle(double radius) 14 { 15 this.radius=radius; 16 } 17 public void setRadius(double radius) 18 { 19 this.radius=radius; 20 } 21 public double getRadius() 22 { 23 return radius; 24 } 25 public double getArea() 26 { 27 double area=PI*radius*radius; 28 return area; 29 } 30 public double getDiameter() 31 { 32 double diameter=radius*2; 33 return radius; 34 } 35 public double getCircumference() 36 { 37 double circumference=2*radius*PI; 38 return circumference; 39 } 40 }
--------------------------------------------------------------------------------
2 import java.util.*; 3 4 5 public class CircleDemo { 6 7 8 public static void main(String[] args) { 9 Scanner keyboard = new Scanner(System.in); 10 double radius; 11 String keepGoing; 12 ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
