Suppose that you work for a beverage company. The company wants to know the optimal cost for a cylindrical container that holds a specified volume. Write a fragment of code that uses an ask-before-iterating loop. During each iteration of the loop, your code will ask the user to enter the volume and the radius of the cylinder. Compute and display the height and cost of the container. Use the following formulas, where V is the volume, r is the radius, h is the height, and C is the cost.


```
double volume = 0.0;
double height = 0.0;
double radius = 0.0;
double cost = 0.0;
String answer;

//Scanner reader = new Scanner(System.in);

do
{
System.out.println("Enter the volume and radius "
+ "of the cylinder ");
volume = reader.nextDouble();
radius = reader.nextDouble();

height = volume / (Math.PI * radius * radius);
cost = 2 * Math.PI * radius *(radius + height);

System.out.println("The height required is: "
+ height + " and the cost is " + cost);

System.out.println("Do you want to compute the "
+ "cost for a different volume & height?");
System.out.println("Enter yes or no.");
answer = reader.next();
} while (answer.equalsIgnoreCase("yes"));
```

This code is in Fragments.java.

Computer Science & Information Technology

You might also like to view...

The value in the middle of a sorted numerical sequence is known as the ____.

A. mode B. median C. average D. range

Computer Science & Information Technology

Modify fig24_06.py so that a user can play, stop, pause and rewind a movie.

What will be an ideal response?

Computer Science & Information Technology

When a new version of a system is installed, the prior release is _____, or stored.?

A. ?archived B. ?deleted C. ?discontinued D. ?reinstalled

Computer Science & Information Technology

A breach of possession may not always result in a breach of confidentiality.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology