Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how could I have the program ask me for the inputValue instead of always having it set one number? public class MeasuementClassCalculationsTest { public static

how could I have the program ask me for the inputValue instead of always having it set one number? public class MeasuementClassCalculationsTest { public static void main(String[] args) { // Scanner object for keyboard input Scanner keyboardInput = new Scanner(System.in); double inputValue = 300; // Prompt the user to select an option System.out.println(" Type an option to perform the operation " + " Option 1: Calculate inches " + " Option 2: Calculate feet " + " Option 3: Calculate yards " + " Option 4: End the Program "); int optionSelected = keyboardInput.nextInt(); keyboardInput.nextLine(); //Consume enter key while (optionSelected != 4) { switch(optionSelected) { case 1: MeasurmentClass cal=new MeasurmentClass(); System.out.println(" Ounces: "+cal.inTOcm(inputValue)); System.out.println(" Kilograms: "+cal.inTOmeter(inputValue)); System.out.println(" Ounces: "+cal.inTOft(inputValue)); System.out.println(" Ounces: "+cal.inTOyd(inputValue)); System.out.println(" Ounces: "+cal.inTOkm(inputValue)); System.out.print(" "); break; case 2: MeasurmentClass cal1=new MeasurmentClass(); System.out.println(" Ounces: "+cal1.ftTOmeter(inputValue)); System.out.println(" Kilograms: "+cal1.ftTOyd(inputValue)); System.out.println(" Ounces: "+cal1.ftTOkm(inputValue)); System.out.println(" Ounces: "+cal1.ftTOmiles(inputValue)); System.out.print(" "); break; case 3: MeasurmentClass cal2=new MeasurmentClass(); System.out.println(" Ounces: "+cal2.ydTOmeter(inputValue)); System.out.println(" Kilograms: "+cal2.ydTOft(inputValue)); System.out.println(" Ounces: "+cal2.ydTOkm(inputValue)); System.out.println(" Ounces: "+cal2.ydTOmile(inputValue)); System.out.print(" "); break; case 4: break; default: System.out.println("Enter a number from 1 to 4 only "); } // End of the switch statement // Prompt the user to select an option System.out.println(" Type an option to perform the operation " + " Option 1: Calculate inches " + " Option 2: Calculate feet " + " Option 3: Calculate yards " + " Option 4: End the Program "); optionSelected = keyboardInput.nextInt(); keyboardInput.nextLine(); //Consume enter key } } }

------------------------------------------------------------------------------------------

public class MeasurmentClass { // Length public static double inTOcm(double inches) { return 2.54 * inches; }public static double inTOmeter(double inches) { return 0.0254 * inches; }public static double inTOft(double inches) { return 0.083333 * inches; }public static double inTOyd(double inches) { return 0.0277778 * inches; }public static double inTOkm(double inches) { return 0.000254 * inches; }public static double ftTOmeter(double feet) { return 0.3048 * feet; }public static double ftTOyd(double feet) { return 0.0003048 * feet; }public static double ftTOkm(double feet) { return 0.33333 * feet; }public static double ftTOmiles(double feet) { return 0.000189394 * feet; }public static double ydTOmeter(double yard) { return 0.914 * yard; }public static double ydTOft(double yard) { return 3.0 * yard; }public static double ydTOkm(double yard) { return 0.00091444 * yard; }public static double ydTOmile(double yard) { return 0.000568182 * yard; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

1. Prepare a flowchart of Dr. Mahalees service encounters.

Answered: 1 week ago