Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago

Question

Question Can life insurance be used in a Keogh (HR 10) plan?

Answered: 1 week ago