Suppose that you work for a beverage company The company wan

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 program 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.

Use 3 digits number and 2 or 3 decimal points in the result/output because they talking about the price/money so it should be 3 digits number only... example: 175.50 or 175.050

V C = 2r(r + h)

Solution

program:

import java.utill.scanner;

Class Volume

{

public static void main(String args[]){

Scanner in = new Scanner(System.in);
System.out.println(\"Enter cylinder volume or -1 to exit:\");
double volume = in.nextDouble();
double radius = 0.0;
if(volume > 0.0)
{
System.out.println(\"Enter cylinder radius:\");
radius = in.nextDouble();
}
while(volume > 0.0)
{
double height = volume / (Math.PI * (radius * radius));
double cost = 2 * Math.PI * radius* (radius + height);
System.out.println(\"Height: \" + h + \"\ Cost: \" + c);
System.out.println(\"Enter cylinder volume or -1 to exit:\");
volume = in.nextDouble();
if(volume > 0.0)
{
System.out.println(\"Enter cylinder radius:\");
radius = in.nextDouble();
}
}

}

}

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 prog

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site