Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package murach.circle; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println( Welcome to the Circle Calculator ); System.out.println(); Scanner sc =

package murach.circle;

import java.util.Scanner;

public class Main {

public static void main(String[] args) { System.out.println("Welcome to the Circle Calculator"); System.out.println();

Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get input from user System.out.print("Enter radius: "); double radius = Double.parseDouble(sc.nextLine());

// create the Circle object Circle circle = new Circle(radius); // format and display output String message = "Area: " + circle.getArea() + " " + "Circumference: " + circle.getCircumference() + " " + "Diameter: " + circle.getDiameter() + " "; System.out.println(message);

// see if the user wants to continue5 System.out.print("Continue? (y/n): "); choice = sc.nextLine(); System.out.println(); } System.out.println("Bye!"); } }

package murach.circle;

public class Circle { private double radius; public Circle() { radius = 0; } public Circle(double radius) { this.radius = radius; }

public double getRadius() { return radius; }

public void setRadius(double radius) { this.radius = radius; } public double getCircumference() { return 2 * 3.14159 * radius; } public double getArea() { return 3.14159 * radius * radius; } public double getDiameter() { return radius * 2; } }

1. Open the Main class and review its code. Note that it only creates one Circle object at a time. 2. Run the application to make sure it works correctly. Modify the application so it stores circles in an array list 3. Before the while loop, add a statement that creates an array list of Circle objects. 4. Within the while loop, add code that adds that Circle object thats created for the specified radius to the array list. 5. After the while loop add another loop that loops through the array list of Circle objects and displays the data for each Circle object on the console. This data should include the radius. To do this, you can move the code that displays the data from the while loop to the second loop. 6. Run the application to make sure it works correctly. If the user enters 100 and 200, the console should look something like this: Enter radius: 100 Continue? (y/n): y Enter radius: 200 Continue? (y/n): n Radius: 100.0 Area: 31415.899999999998 Circumference: 628.318 Diameter: 200.0 Radius: 200.0 Area: 125663.59999999999 Circumference: 1256.636 Diameter: 400.0 However, this should also work if the user enters one radius or if the user enters more than two radiuses.

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 Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago