 Cylinder Containers in Java

Subject Computer Science Java Programming

Question

Suppose that your 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 and ask-before-iteration 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.
h =V/(π r * r)
C = 2πr(r + h)

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class Container{

public static void main(String[] args){
Scanner in = new Scanner(System.in);

System.out.print("Please enter the volume of the cylinder or 0 to exit: ");
double volume = in.nextDouble();

System.out.print("Please enter the radius of the cylinder or 0 to exit: ");
double radius = in.nextDouble();

while (volume > 0 && radius > 0) {

double height = volume / (Math.PI * Math.pow(radius, 2));...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Explanation For Java Classes \$30.00
Java
Programming
Computer Science
Codes
Classes
Inheritance
Comparator
Binary Matrix
Labels
Edges
Tree
Strings
Integers
Nodes
Temporary Storage
Statements
Variables
Species
HashSet
Iterator
Java Programming: Nested Statements, Grid of Numbers & Binary Integers \$20.00
Java
Programming
Computer Science
Grid of Numbers
Nested Statements
Loops
Binary Integers
Codes
Conversions
Input
Output
Java Programming Assignment \$30.00
Java Programming
Computer Science
Arrays
Submatrix
Substitution Method
Variable
Java Programming Assignment \$20.00
Java Programming
Computer Science
Calculator Application
Employee
Pay
Array Problems in Java: Summation, Average, Min/Max, Searching, Sorting \$13.00
Java
Programming
Coding
Computer Science
Arrays
Summation
Average
Minimum Number
Maximum Number
Bubble Sort
Selection Sort
Sequential Search
Binary Search
Algorithms
Input
Output
Methods
Integers
Functions
Live Chats