Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

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. Your output should be of the form: 32.0F equals 0.0C ============================================================ Following is my solution in which i need to use JavaFX: import java.util.Scanner; public class TemperatureConversion { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); char convertFrom = 'C'; double celsius=0.0; double fahrenheit=0.0; double celsius_result=0.0; double temprature_result=0.0;// 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': celsius=scnr.nextDouble(); temprature_result=CelsiusToFahrenheit(celsius); System.out.println(celsius+"C equals "+temprature_result+"F"); break; case 'F': fahrenheit=scnr.nextDouble(); celsius_result=FahrenheitToCelsius(fahrenheit); System.out.println(fahrenheit+"F equals "+celsius_result+"C"); break; default: System.out.println("Wrong Choice:"); } scnr.close(); } private static double FahrenheitToCelsius(double fahrenheit) { double celsius=0.0; celsius=(fahrenheit-32)*5.0/9; return celsius; } private static double CelsiusToFahrenheit(double celsius) { double fahrenheit=0.0; fahrenheit=celsius*9.0/5+32; return fahrenheit; } } =================== I need to use JavaFX in my solution.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions