Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Distance Conversion

mattworley
mattworley 


Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections: 1. Convert to Kilometers 2. Convert to inches 3. Convert to feet 4. Quit the program Programming Assignment # 9 A. Purpose of Program Using void and value-returning methods. B. Required Reading Chapter 5 C. Exercise Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections: 1. Convert to kilometers 2. Concert to inches 3. Convert to feet 4. Quit the program The program will convert the distance to kilometers, inches, or feet, depending on the user’s selection. Here are the specific requirements: • Write a void method named showKilometers, which accepts the number of meters as an argument. The method should display the argument converted to kilometers. Concert 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. Concert 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 feet. Concert the meters to feet using the following formula: feet = meters * 3.281 • Write a void method named menu, that displays the menu of selection. This method should not accept any arguments. • The program should continue to display the menu until the user enters 4 to quit the program. • The program should not accept negative numbers for the distance in meters. • If the user selects an invalid choice from the menu, the program should display an error messages.D. Notes and Comments Remember that the project name is pass9 and the Java file name will be your last name with pass9. Be sure to compile your program, correct any syntax errors, recompile until no errors, than test the program with different values. Make sure your program has comments that include your name, CSCI 1015, Programming Assignment 9, and the purpose of the program. Upload the java file to D2L drop box folder named Pass9. E. Example input and output Here is an example session with the program, using console input. The user’s input is show in red and bold. Enter a distance in meters: 500 1. Convert to kilometers 2. Convert to inches 3. Convert to feet 4. Quit the program Enter your choice: 1 500.0 meters is 0.5 kilometers. 1. Convert to kilometers 2. Convert to inches 3. Convert to feet 4. Quit the program Enter your choice: 2 500.0 meters is 19685.0 inches. 1. Convert to kilometers 2. Convert to inches 3. Convert to feet 4. Quit the program Enter your choice: 5 Invalid selection. Enter your choice: 4 Bye! Attachments Tags Clarifications

Answers

Distance Conversion - Solution

dickersonka
dickersonka 



Attached is the solution to the Distance Conversion assignment including source and comments Attachments
LastNamepass9.java (2 K) Download Preview
System.out.print("Enter your choice: "); menuChoice = input.nextInt(); } //display output based on choice switch (menuChoice) { case 1: showKilometers(distanceInMeters); break; case 2: showInches(distanceInMeters); break; case 3: showFeet(distanceInMeters); break; case 4: quit = true; System.out.println("Bye!"); break; default: continue; } } } /** * Convert meters to kilometers */ private static

Meters_output.png (12 K) Download Preview

Screenshots
Screenshot
Purchase Answer

Distance Conversion - Solution

mariobeka
mariobeka 



Below you will find the java file requested, following the rules of the pdf file you provided. A Screenshot of the program working is also attached by. Attachments
LastNamepass9.java (1 K) Download Preview
" + kilometers + " kilometers.\n"); } /** * Convert meters to inches */ private static void showInches(double meters) { double inches = 0.0; inches = meters * 39.37; System.out.println(meters + " meters is " + inches + " inches.\n"); } /** * Convert meters to feets */ private static

Screen Shot 2014-09-20 at 12.32.45 AM.png (101 K) Download Preview

Screenshots
Screenshot
Purchase Answer

DistanceConverter

uetian_cute
uetian_cute 



Attached are the code file and a screenshot of output Attachments
DistanceConversion.java (3 K) Download Preview
* * @param meters * @return the number of kilometers */ static double calculateKilometers(double meters) { double kilometers = meters * 0.001; return kilometers; } /** * This method should calculate inches that are equivalent to a

Capture.PNG (20 K) Download Preview

Screenshots
Screenshot
Purchase Answer