You are going to convert temperatures in this program. You will give the user th
ID: 3810910 • Letter: Y
Question
You are going to convert temperatures in this program.
You will give the user the choice of converting Fahrenheit to Celsius or Celsius to Fahrenheit. Display the number entered and the correct answer. See the requirements below:
There will be a Main() for testing each file/class that you create
You will have a menu for this assignment. This means a separate file/class called conversionMenu.java
You will have the temperature conversion functions in a file/class called tempConversions.java
Your Main() that runs the whole program is going to be in a file called “yourlastname” Assignment4.java So mine would be called schuettAssignment4.java
The user can convert either Fahrenheit to Celsius or Celsius to Fahrenheit as many times as they want to
After each conversion the user will see what they entered and the correct answer.
Following “F” the user will also see the menu again
You will also need to use printf for all output
Don’t forget to add your heading class and display that information at the beginning of the program as well as thanking them at the end
The formulas are: centigrade = (fahrenheit - 32) * 5/9 fahrenheit = centigrade * 9/5 + 32
Trivia: the brains behind: Anders Celsius,
Swedish physicist and astronomer, 1701 – 1744 Gabriel Fahrenheit,
German physicist, 1686 - 1736, inventor of the thermometer How did they choose the ranges?
CELSIUS: range of 100 steps, 0 degree Centigrade = freezing point of water, 100 degree Centigrade = boiling point of water FAHRENHEIT: range of 180 steps, 32 degree Fahrenheit = freezing point of water, 100 degree Fahrenheit = body temperature of a person (not very accurate...), 212 degree Fahrenheit = boiling point of water
Explanation / Answer
schuettAssignment4.java
import java.io.*;
import java.util.*;
public class schuettAssignment4
{
public static void main(String[] args)
{
conversionMenu cm = new conversionMenu();
while (true)
{
System.out.println("Enter m or M to open menu, otherwise enter q or Q for the final stats");
Scanner scan = new Scanner(System.in);
String entered = scan.next();
switch(entered)
{
case "m":
case "M":
cm.Menu();
break;
case "q":
case "Q":
System.exit(0);
default:
System.err.println("Please enter a valid character");
}
}
}
}
conversionMenu.java
import java.io.*;
import java.util.*;
public class conversionMenu
{
public void Menu()
{
tempConversions tc = new tempConversions();
while (true)
{
System.out.println("Enter 1 for converting Fahrenheit to Celsius, enter 2 for converting Celsius to Fahrenheit and 3 for exiting from the menu.");
Scanner scan = new Scanner(System.in);
String entered = scan.next();
switch(entered)
{
case "1":
System.out.println("Enter the Fahrenheit");
float Fahrenheit = scan.nextFloat();
System.out.println(tc.FahrenheitToCelsius(Fahrenheit)+" centigrade");
System.out.println("Thank you!");
break;
case "2":
System.out.println("Enter the Celsius");
float Celsius = scan.nextFloat();
System.out.println(tc.CelsiusToFahrenheit(Celsius)+" fahrenheit");
System.out.println("Thank you!");
break;
case "3":
System.exit(0);
default:
System.err.println("Please enter a valid option.");
}
}
}
}
tempConversions.java
public class tempConversions
{
public float FahrenheitToCelsius(float fahrenheit)
{
float centigrade = (fahrenheit - 32) * 5/9;
return centigrade;
}
public float CelsiusToFahrenheit(float centigrade)
{
float fahrenheit = centigrade * 9/5 + 32;
return fahrenheit;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.