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

Code must use multiple \"methods\" and output must match the example. Thank you!

ID: 3872673 • Letter: C

Question

Code must use multiple "methods" and output must match the example. Thank you! Problem 4-Volume and Weight Converter [30 points Write a program called Volume and Weight Converter (VolumeWeightConverter java) that will perform the following conversions Gallon to Liter . .Liter to Gallon Pound to Kilogram Kilogram to Pound . . In your main method, display a menu with each of these choices plus an additional choice to exit. P option, then call the corresponding methgd to prompt for a value and display the converted result. user for a menu Your resulting program should have five methods: main and one method for each of the conversion functions. The calculation must be performed in those four methods, and the result should be printed from the main method. After the converted value is displayed, display the menu again and repeat until the user chooses the Exit option. Hints: Your menu and the calls to the other methods must be inside a loop. Use double values, not int values. format the output. Use printf to Create the following four methods in addition to your main method: Method gallons ToLiters gallons 3.785 liters ToGallons liters 0.264 pounds ToKilograms pounds.0.454 kilograms ToPounds kilograms 2.205 Calculation

Explanation / Answer

import java.io.*;

import java.util.Scanner;

class converter

{

double gallon;

double liter;

double pound;

double kilogram;

double gallontoliter(double g)

{

gallon=g;

return gallon*3.785;

}

double litertogallon(double l)

{

liter=l;

return liter*0.264;

}

double poundstokg(double p)

{

pound=p;

return pound*0.454;

}

double kgtopound(double k)

{

kilogram=k;

return kilogram*2.205;

}

}

class VolumeWeightConverter

{

public static void main(String args[])

{

int ch=0;

converter c=new converter();

Scanner s=new Scanner(System.in);

System.out.printf("1:gallons to liters 2:liters to gallons 3:pound to killogram 4: kilogram to pounds ");

do

{

System.out.printf(" enter your choice ");

ch=s.nextInt();

switch(ch)

{

case 1:

try{

System.out.printf("enter gallon value:");

DataInputStream dis1=new DataInputStream(System.in);

double g=Integer.parseInt(dis1.readLine());

double lit=c.gallontoliter(g);

System.out.printf(" " +g+ " "+ "gallon="+" "+lit+" "+"liters");

}

catch(Exception e)

{

}

break;

case 2:

try{

System.out.printf("enter liter value:");

DataInputStream dis2=new DataInputStream(System.in);

double l=Integer.parseInt(dis2.readLine());

double gal=c.litertogallon(l);

System.out.printf(" " +l+ " "+ "liters="+" "+gal+" "+"gallons");

}

catch(Exception e)

{

}

break;

case 3:

try{

System.out.printf("enter pound value:");

DataInputStream dis3=new DataInputStream(System.in);

double p=Integer.parseInt(dis3.readLine());

double kg=c.poundstokg(p);

System.out.printf(" " +p+ " "+ "pounds="+" "+kg+" "+"kilogram");

}

catch(Exception e)

{

}

break;

case 4:

try{

System.out.printf("enter kilogram value:");

DataInputStream dis4=new DataInputStream(System.in);

double k=Integer.parseInt(dis4.readLine());

double po=c.kgtopound(k);

System.out.printf(" " +k+ " "+ "kilogram="+" "+po+" "+"pounds");

}

catch(Exception e)

{

}

break;

default:System.out.printf("ended program ");

}

}while(ch!=5);

}

}

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