Question

Program must be in JAVA. Write a program that converts temperature from Celsius to Fahrenheit or...

Program must be in JAVA.

Write a program that converts temperature from Celsius to Fahrenheit or vice versa, depending on user's input.

The formula for converting temperature in Celsius to Fahrenheit is,

Fahrenheit = (9/5) * Celsius + 32

The formula for converting temperature in Fahrenheit to Celsius is,

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

Results should be rounded to two decimal points, e.g., 92.56

Homework Answers

Answer #1

import java.util.Scanner;
public class temp {

       public static double celsius_To_Fahrenheit(double degree_C)
       {
       double fahrenheit_Result = (9*(degree_C) / 5) + 32;
       return fahrenheit_Result;
       }

       public static double fahrenheit_To_Celsius(double degree_F)
       {
       double celsius_Result = 5*(degree_F - 32)/9;
       return celsius_Result;
       }

       public static void init(){
       Scanner scan = new Scanner(System.in);
       double result;
       char cont= 'y';
       char type;


       while (cont!='q' && cont!='Q')
       {
       System.out.println("Please enter the degree:");
       double degree = scan.nextDouble();

       System.out.println("Now enter the type of conversion (For Celsius, type 'C'. For Fahrenheit, type 'F')");
       type = scan.next().charAt(0);

       if(type!='c' && type!='C' && type!='f' && type!='F')
       {
       System.out.println("Error! You've entered an invalid conversion type!");
       System.out.println("Please enter a valid selection (Type C for celsius and F for fahrenheit");
       type = scan.next().charAt(0);
       }
       if (type == 'F' || type =='f')
       {
       result = fahrenheit_To_Celsius(degree);
       System.out.println("The conversion of "+ degree+"°F "+ "to Celsius is: " + Math.round(result * 100.0) / 100.0 + "°C");

       }
       if (type == 'C' || type =='c')
       {
       result = celsius_To_Fahrenheit(degree);
       System.out.println("The conversion of "+ degree+"°C "+ "to Fahrenheit is: " + Math.round(result * 100.0) / 100.0 + "°F");
       }


       System.out.println("Would you like to quit? Type 'q' to quit or type any other letter to continue:");
       cont = scan.next().charAt(0);
       }
       scan.close();
       }

       public static void main(String[] args)
       {
       init();
       }
}

Code Image:

Output Image:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a java program that asks for temperature in Fahrenheit. The program should accept any floating...
Write a java program that asks for temperature in Fahrenheit. The program should accept any floating point number. Display whether water is liquid, solid, or gas at that temperature at sea level. Display the results like this: “Water at that temperature is a solid/liquid/gas.” (Note: display only the correct state for that temperature.) water freezes at 32 degrees F and boils at 212 degrees F.
C++ Fahrenheit to Celsius Tables Write a program that first asks the user which Temperature scale...
C++ Fahrenheit to Celsius Tables Write a program that first asks the user which Temperature scale conversion he/she would like to perform: 1. Convert F to C 2. Convert C to F 3. Quit What is your choice? Then it asks the user for input for three real number variables: start_temp, end_temp, temp_incr. It will then produce a two column Fahrenheit to Celsius table or a two column Celsius to Fahrenheit table, depending on the choice. For choice 1, the...
Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to...
Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to 120F and their equivalent Celsius temperatures. Each line in the table should be 5 degrees F more than the previous one. Both the Fahrenheit and Celsius temperatures should be accurate to 1 decimal place. I am not able to use: import java.text.DecimalFormat; Any feedback would be helpful.
Please use C++ programming language write a program to convert temperature in Fahrenheit to temperature in...
Please use C++ programming language write a program to convert temperature in Fahrenheit to temperature in celcius.( no comments necessary). get the temperature in Fahrenheit. calculate the temperature in Celsius. and write  the output to screen. Celsius = (5/9) * (F-160)
Use Python: the formula for converting a temperature from Fahrenheit to Celcius is C=5/9(f-32) where F...
Use Python: the formula for converting a temperature from Fahrenheit to Celcius is C=5/9(f-32) where F is the Fahrenheit temperatre and C is the celcius temperature. Write a function named celcius that accepts a Fahrenheit temperature as an argument. the function should return the temperature, convertedm to celcius. Demonstrate the function by calling it in a loop that displays a table of the fahrenheit temperatures 0 through 20 and their Celsius equivalents.
Please write a program to calculate the area of a circle. Area =3.14*Radius*Radius. Input Radius. Please...
Please write a program to calculate the area of a circle. Area =3.14*Radius*Radius. Input Radius. Please write a program to calculate the area of a rectangle. Area =Width*Length. Input Width and Length. Please write a program to covert Fahrenheit degree to Celsius degree. The formula is C=(F-32)*5/9. Input Fahrenheit degree. Please write a program to covert Celsius degree to Fahrenheit degree. The formula is F=C*9/5+32. Input Celsius degree.
3. The following is the formula to convert a Celsius degree to Fahrenheit degree: Fahrenheit =...
3. The following is the formula to convert a Celsius degree to Fahrenheit degree: Fahrenheit = (9/5) Celsius + 32 Write a program to prompt user to enter a Celsius degree, convert it to Fahrenheit and display Given an integer value which is the measurement of weight in ounce. Convert it to the format of: x pounds and y ounces. For example, if the given number is 100 ounces, it will be represented as 6 pounds and 4 ounces after...
Write a Matlab function convert T such that convert T(x, ’C’) converts from degrees Celsius to...
Write a Matlab function convert T such that convert T(x, ’C’) converts from degrees Celsius to degrees Fahrenheit, while convert T(x, ’F’) converts from Fahrenheit to Celsius. Need to submit program online to see if successful. Please help! function T = convert_T (x, flag) %convert between Celsius and Fahrenheit temperatures %for example, convert_T(10, 'C') should return 50 %and convert_T(50, 'F') should return 10
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
In c++ format please Most people know that the average human body temperature is 98.6 Fahrenheit...
In c++ format please Most people know that the average human body temperature is 98.6 Fahrenheit (F). However, body temperatures can reach extreme levels, at which point the person will likely become unconscious (or worse). Those extremes are below 86 F and above 106 F. Write a program that asks the user for a body temperature in Fahrenheit (decimals are ok). Check if that temperature is in the danger zone (for unconsciousness) or not and produce the relevant output shown...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT