Question: Question Modify the program and create two methods to convert from Celsius to Fahrenheit and vice versa. public static double CelsiusToFahrenheit (double Celsius) public static

Question

Modify the program and create two methods to convert from Celsius to Fahrenheit and vice versa.

public static double CelsiusToFahrenheit (double Celsius) public static double FahrenheitToCelsius (double Fahrenheit)

Formulae for the conversion:

Fahrenheit = Celsius * 9 / 5 + 32 Celsius = (Fahrenheit 32) * 5 / 9

Hint 1: Please consider using a well-known F to C and/or C to F calculator such as what you may find in a simple Google search to double-check your work.

Hint 2: If you are an individual who likes to use parenthesis to more clearly show your calculations, be sure to take typecasting into account when dealing with your fractions. Refer to Chapter 2 for a refresher, if necessary.

Code

import java.util.Scanner;

public class TemperatureConversion {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

char convertFrom = 'C';

// FIXME: Declare two variables in double data type to store the input and output temperatures; Assign the value 0.0

// Prompt the user to select converting to degree C or degree F

do {

System.out.println("Convert from degree C, enter C; Convert from degree F, enter F: ");

convertFrom = Character.toUpperCase(scnr.next().charAt(0));

} while (!((convertFrom == 'C') || (convertFrom == 'F')));

// FIXME: Complete the following to obtain user input

System.out.println("Enter degree in " + convertFrom + ": ");

/*

FIXME: Complete the switch statements

To convert to degree C, call the FahrenheitToCelsius method

To convert to degree F, call the CelsiusToFahrenheit method

*/

switch (convertFrom) {

case 'C':

break;

case 'F':

break;

}

}

// FIXME: Create a method to convert from Celsius to Fahrenheit

// FIXME: Create a method to convert from Fahrenheit to Celsius

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!