Question: You are given the class Circle.java. Download into your IDE of choice. Create a second Java class titled CircleArray with a main method. In the
You are given the class Circle.java. Download into your IDE of choice. Create a second Java class titled CircleArray with a main method. In the main method, create an array or ArrayList to hold three (3) Circle objects. Using an appropriate loop (hint : for loop), create each Circle object and ask the user for a radius for each new Circle object. Set the radius and store the new Circle object in the array or ArrayList. After the loop completes, code a second loop to computer area and print radius and area for each Circle in the array.
Do NOT edit Circle.java and turn in new CircleArray.java file.
/**
* Circle.java
*
* Starter class for Chapter 1 array of objects coding assignment
*
*/
public class Circle
{
private double radius;
public Circle()
{
}
public Circle(double radius)
{
this.radius = radius;
}
/** Return radius */
public double getRadius()
{
return radius;
}
/** Set a new radius */
public void setRadius(double radius)
{
this.radius = radius;
}
public double getArea()
{
return radius * radius * Math.PI;
}
/** Return diameter */
public double getDiameter()
{
return 2 * radius;
}
public double getPerimeter()
{
return 2 * radius * Math.PI;
}
/* Print the circle info */
public void printCircle()
{
System.out.println("The circle radius is " + radius);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
