Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert This Program To A Class and develop a Demo To Test The class: package vo

ID: 3660829 • Letter: C

Question

Convert This Program To A Class and develop a Demo To Test The class:


package volumeofcylindercalculator;



import java.util.Scanner;


/**

*

* W02 - Carl Simpson

*/

public class VolumeOfCylinderCalculator {


/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner KB = new Scanner(System.in);

System.out.println("***This Program Calculates The Height & Cost Of A Soda Based On Its Volume And Radius***");

System.out.println();

System.out.println("Enter cylinder volume or -1 to exit:");

double v = KB.nextDouble();

double r = 0;

if(v > 0)

{

System.out.println("Enter cylinder radius:");

r = KB.nextDouble();

}

while(v > 0)

{

double h = v / (Math.PI * (r * r));

double c = 2 * Math.PI * r * (r + h);

System.out.println();

System.out.printf("Height: %6.2f ", h);System.out.printf("Cost:$ %6.2f ", c);

System.out.println();

System.out.println("Enter cylinder volume or -1 to exit:");

System.out.println();

v = KB.nextDouble();

if(v > 0)

{

System.out.println("Enter cylinder radius:");

r = KB.nextDouble();

}

}

}

}

Explanation / Answer

import java.util.Scanner; public class VolumeOfCylinderCalculator { public static void main(String[] args) { Scanner KB = new Scanner(System.in); Cylinder cil = new Cylinder(); System.out.println("***This Program Calculates The Height & Cost Of A Soda Based On Its Volume And Radius***"); System.out.println(); System.out.println("Enter cylinder volume or -1 to exit:"); double v = KB.nextDouble(); double r = 0; if(v > 0) { System.out.println("Enter cylinder radius:"); r = KB.nextDouble(); } while(v > 0) {    double h = cil.FindHeight(v, r); double c = cil.FindCost(v, r, h); System.out.println(); System.out.printf("Height: %6.2f ", h); System.out.printf("Cost:$ %6.2f ", c); System.out.println(); System.out.println("Enter cylinder volume or -1 to exit:"); System.out.println(); v = KB.nextDouble(); if(v > 0) { System.out.println("Enter cylinder radius:"); r = KB.nextDouble(); } } } } import java.util.Scanner; public class VolumeOfCylinderCalculator { public static void main(String[] args) { Scanner KB = new Scanner(System.in); Cylinder cil = new Cylinder(); System.out.println("***This Program Calculates The Height & Cost Of A Soda Based On Its Volume And Radius***"); System.out.println(); System.out.println("Enter cylinder volume or -1 to exit:"); double v = KB.nextDouble(); double r = 0; if(v > 0) { System.out.println("Enter cylinder radius:"); r = KB.nextDouble(); } while(v > 0) {    double h = cil.FindHeight(v, r); double c = cil.FindCost(v, r, h); System.out.println(); System.out.printf("Height: %6.2f ", h); System.out.printf("Cost:$ %6.2f ", c); System.out.println(); System.out.println("Enter cylinder volume or -1 to exit:"); System.out.println(); v = KB.nextDouble(); if(v > 0) { System.out.println("Enter cylinder radius:"); r = KB.nextDouble(); } } } } public class Cylinder { public double FindHeight(double v, double r) { return v / (Math.PI * (r * r)); } public double FindCost(double v, double r, double h) { return 2 * Math.PI * r * (r + h); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote