Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I modify the code to calculate the areas of circles with radius = 1, 10, 100 Only one .java file. public class TotalArea

How can I modify the code to calculate the areas of circles with radius = 1, 10, 100 Only one .java file.

public class TotalArea {

public static void main(String[] args) {

CircleWithPrivateDataFields[] circleArray;

circleArray = createCircleArray();

printCircleArray(circleArray);

}

public static CircleWithPrivateDataFields[] createCircleArray() {

CircleWithPrivateDataFields[] circleArray = new CircleWithPrivateDataFields[5];

for (int i = 0; i < circleArray.length; i++) {

circleArray[i] = new CircleWithPrivateDataFields(Math.random() * 100);

}

return circleArray;

}

public static void printCircleArray(CircleWithPrivateDataFields[] circleArray) {

System.out.printf("%-30s%-15s ", "Radius", "Area");

for (int i = 0; i < circleArray.length; i++)

{ System.out.printf("%-30f%-15f ", circleArray[i].getRadius(), circleArray[i].getArea());

}

System.out.println("-----------------------------------------");

System.out.printf("%-30s%-15f ", "The total areas of circles is", sum(circleArray));

}

public static double sum(CircleWithPrivateDataFields[] circleArray) {

double sum = 0;

for (int i = 0; i < circleArray.length; i++)

sum += circleArray[i].getArea();

return sum;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

Explain walter's model of dividend policy.

Answered: 1 week ago