Question: Java programming through eclipse. Add two new options to the code provided, in addition to the two already there: Covert feet to meters Convert meters
Java programming through eclipse.
Add two new options to the code provided, in addition to the two already there:
Covert feet to meters
Convert meters to feet
Add these options to the menu. Add input, conversion and output methods.
Leave the degree methods in, add these new features to what already exists
import java.util.*;
public class degrees3 {
public static void main(String[] args) { double c, f; Scanner keyboard = new Scanner(System.in);
char choice; do{ choice = menu(keyboard); switch(choice){ case 'a': f = inputF(keyboard); c = fahrenheitToCelsius(f); displayResults(f, c); break; case 'b': c = inputC(keyboard); f = celsiusToFaherenheit(c); displayResults(f,c); break; } }while(choice != 'q'); keyboard.close(); } public static char menu(Scanner keyboard){ char results; boolean done; do{ done = true; System.out.println(" Choose from the following: "); System.out.println("A. Convert Fahrenheit to Celsius"); System.out.println("B. Convert Celsius to Fahrenheit"); System.out.println("Q. Quit"); results= keyboard.next().toLowerCase().charAt(0); if(results != 'a' && results != 'b' && results != 'q'){ System.out.println("Error! enter A, B, or Q"); done = false; } }while(!done); return results; }
public static double fahrenheitToCelsius(double f){ return (5.0 / 9) * (f - 32); }
public static double celsiusToFaherenheit(double c){ return (9.0/5)*c + 32; } public static double inputF(Scanner input){ double f; System.out.print("Enter degrees F: "); f = input.nextDouble(); while(f < -459.67){ System.out.print("Error. Must be -459.67 or more. "); System.out.print("Enter degrees F: "); f = input.nextInt(); } return f; } public static double inputC(Scanner input){ double c; System.out.print("Enter degrees C: "); c = input.nextDouble(); while(c < -273.15){ System.out.print("Error. Must be -273.15 or more. "); System.out.print("Enter degrees C: "); c = input.nextInt(); } return c; }
public static void displayResults(double f, double c){ System.out.println("Results as follows: "); System.out.printf("%2.2f Fahrenheit ", f); System.out.printf("%2.2f Celsius ", c); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
