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

Develop and test a Java program as follows: Present the user with a menu to conv

ID: 3698265 • Letter: D

Question

Develop and test a Java program as follows:

Present the user with a menu to convert the following:

1. Ounces to grams

2. grams to ounces

3. pounds to kilograms

4. kilograms to pounds

5. feet to meters

6. meters to feet

7. miles to kilometers

8. kilometers to miles

Use a Java switch statement to determine the user's input and perform the conversion according to the conversion factors shown below. The program should display each instance (input data and output string). Add a do ... while structure around the switch structure allowing the user to repeat the program as many times as needed. Allow for a menu item (usually the last menu item) for the user to exit the program.

Use int data type for the menu selections. use double data types for the conversion units.

1 ounce = 28.375 grams

1 gram = 0.035 ounces

1 pound = 0.454 kilograms

1 kilogram = 2.204 grams

1 mile = 1.6 kilometers

1 kilometer = 0.6 miles

1 foot = 0.3 meters

1 meter = 3.3 feet

Explanation / Answer

import java.util.*;
public class HelloWorld{

     public static void main(String []args){
         int choice;
         double input,output;
         Scanner read=new Scanner(System.in);
         do
         {
             System.out.println("Enter your choice");
             System.out.println("1. Ounces to grams"+
                           " 2. grams to ounces"+
                           " 3. pounds to kilograms"+
                           " 4. kilograms to pounds"+
                           " 5. feet to meters"+
                           " 6. meters to feet"+
                           " 7. miles to kilometers"+
                           " 8. kilometers to miles"+
                           " 9.Quit");
            choice=read.nextInt();
            switch(choice)
            {
                case 1: System.out.print("Enter no of ounces: ");
                        input=read.nextDouble();
                        output=input*28.375;
                        System.out.println("Ounces :"+input);
                        System.out.println("Grams: "+output);
                        break;      
                case 2: System.out.print("Enter no of grams: ");
                        input=read.nextDouble();
                        output=input*0.035;
                        System.out.println("Grams :"+input);
                        System.out.println("Ounces: "+output);
                        break;
                case 3: System.out.print("Enter no of pounds: ");
                        input=read.nextDouble();
                        output=input*0.454;
                        System.out.println("Pounds :"+input);
                        System.out.println("Kilograms:"+output);
                        break;
                case 4: System.out.print("Enter kilogram units: ");
                        input=read.nextDouble();
                        output=input*2.202;
                        System.out.println("Kilograms :"+input);
                        System.out.println("Pounds: "+output);
                        break;
                case 5: System.out.print("Enter units of foot: ");
                        input=read.nextDouble();
                        output=input*0.3;
                        System.out.println("Feet:"+input);
                        System.out.println("Meters: "+output);
                        break;
                case 6: System.out.print("Enter units of meters: ");
                        input=read.nextDouble();
                        output=input*3.3;
                        System.out.println("Meters :"+input);
                        System.out.println("Feet: "+output);
                        break;
                case 7: System.out.print("Enter no of miles: ");
                        input=read.nextDouble();
                        output=input*1.6;
                        System.out.println("Miles :"+input);
                        System.out.println("Kilometers: "+output);
                        break;
                case 8: System.out.print("Enter no of kilometers: ");
                        input=read.nextDouble();
                        output=input*0.6;
                        System.out.println("Kilometers :"+input);
                        System.out.println("Miles: "+output);
                        break;
                case 9: System.exit(0);
            }
         }while(choice!=9);
     }
}