Question
DESCRIPTION Create a program that: 1) Asks the user for a temperature (allow decimal values). 2) Asks the user for the scale used for the
DESCRIPTION
Create a program that:
1) Asks the user for a temperature (allow decimal values).
2) Asks the user for the scale used for the temperature, Fahrenheit or Celsius, by entering either "F" or "C" (as a String)
3) Calculate the conversion of the given temperature to the other scale, e.g., if the user entered a Celsius temperature, calculate and print the Fahrenheit equivalent or vice-versa.
Recall the temperature conversion formulas:
F = 9/5 (C) + 32
C = 5/9 (F-32)
* Be careful to avoid integer division!
Sample output:
Enter a temperature: 80 Is that Fahrenheit (F) or Celsius (C)? F 80.0 degrees Fahrenheit is 26.666666666666668 degrees Celsius
STARTER CODE:
import java.util.Scanner;
public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature
//ask the user for the scale of the temperature
//convert to Celsius if given temperature was Fahrenheit //convert to Fahrenheit if given temperature was Celsius } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started