[solved] – Question 8544
// Qs. Write java program that contains the following 2 classes.
(i) Circle class that contains a radius field and getArea method that calculates its area.Give it a constructor where u pass in the radius.
(ii) TestCircle class which creates an array of 100 circles, each with a a random radius and prints out the sum of the areas , the biggest & smallest areas
class Circle {
private float radius;
public Circle(float r)
{
this.radius=r;
}
public float getArea()
{
return (float)(Math.PI*radius*radius);
}
}
class circle7
{
public static void main(String[] args)
{
Circle circles[]= new Circle[100];
for(int i=0; i<circles.length; i++)
{
circles[i]= new Circle((float)(50*Math.random()));
showAreas(circles);
System.out.println(“the sum is”+ areaSum(circles));
System.out.println(“the minimum is”+ minArea(circles));
System.out.println(“the maximum is”+ maxArea(circles));
}
public static float areaSum(Circle c[])
{
float sum= 0;
for(int i=0; i<c.length; i++)
{
sum+= c[i].getArea();
}
return sum;
}
public static float minArea(Circle c[])
{
float min= c[0].getArea();
for(int i=1; i<c.length; i++)
{
if(c[i].getgetArea()<min)
min= c[i].getArea();
}
return min;
}
public static float maxArea(Circle c[])
{
float max= c[0].getArea();
for(int i=1; i<c.length; i++)
{
if(c[i].getgetArea()>max)
max= c[i].getArea();
}
return max;
}
public static void showAreas(Circle c[])
{
for(int i=0; i<c.length; i++)
{
System.out.println(c[i].getArea());
}
}
}
// Can someone plz find the errors in the program? Cuz the compiler is giving 8 errors.
Expert Answer
OR

