Question
Conversion Program in Java netbeans Write a program that asks the user to enter a distance in meters. The program will present two menus to
Conversion Program in Java netbeans
Write a program that asks the user to enter a distance in meters.
The program will present two menus to the user:
An outer menu will prompt for a new value for distance in meters, or to quit the program:
- Enter distance in meters
- Quit the program
When the user selects Option 1 and then enters a value for distance, a second menu of selections will be offered for the type of conversion, with an option to return to enter a new distance:
- Convert to kilometers
- Convert to inches
- Convert to feet
- Return to enter distance
The program should thus operate with an inner and outer loop, allowing the user to make conversions with different distances until they decide to quit.
The program must implement at least the following methods. (You are free to add additional methods if you choose.) Here are the specific requirements:
- The main method should have a loop that runs until the user decides to quit. Within the loop the conversionControl() method will be called, and passed the value the user enters for meters.
- Write a void method named conversionControl(). This method will accept the number of meters as an argument. This method will control the operation of the inner loop and will call the various show methods that the user chooses.
- Write a void method named showKilometers, which accepts the number of meters as an argument. The method should display the argument converted to kilometers. Convert the meters to kilometers using the following formula:
- Kilometers = meters * 0.001
- Write a void method named showInches, which accepts the number of meters as an argument. The method should display the argument converted to inches. Convert the meters to inches using the following formula:
- Inches = meters * 39.37
- Write a void method named showFeet, which accepts the number of meters as an argument. The method should display the argument converted to feel. Convert the meters to feet using the following formula:
- Feet = meters * 3.281
- Write a void method named menu that displays the menu of selections. This method should not accept any arguments. The menu method should call the appropriate conversion method based on the user choice. For example, if the user selects Option 1, then the showKilometers method will be called. The menu method will loop to display the menu until the user enters 4 to quit the program.
- The program should not accept negative numbers or non-numeric values for the distance in meters. You should loop until a valid value is entered.
- If the user selects an invalid choice from the menu, the program should display an error message and redisplay the message and wait for the next choice.
Example of what output is expected
1. Perform conversion 2. Quit the program Please enter your choice: 1 Enter a distance in meters: 500 Conversion Menu 1. Convert to kilometers 2. Convert to inches 3. Convert to feet 4. Return Enter your choice:1 500 meters is 0.5 kilometers Conversion Menu 1. Convert to kilometers 2. Convert to inches 3. Convert to feet 4. Return Enter your choice: 3 500 meters is 1640.5 feet Conversion Menu 1. Convert to kilometers 2. Convert to inches 3. Convert to feet 4. Return Enter your choice: 4 Main Menu 1. Perform conversion 2. Quit the program Please enter your choice: 2 Good byeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started