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

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use 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.
By purchasing this solution you'll be able to access the following files:
Solution.java
Purchase Solution
$25.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
ionut
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,806+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,696+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,467+ sessions)
2 hours avg response

Similar Homework Solutions