Question

In: Computer Science

(java))Write a “Temperature Conversion” program. Declare choice, tempIn, tempOut variables Prompt the user with the messages...

(java))Write a “Temperature Conversion” program.

Declare choice, tempIn, tempOut variables

Prompt the user with the messages to choose: 1) Centigrade to Fahrenheit, 2) Fahrenheit to centigrade.

Prompt the user for temperature value (tempIn) to convert.

Calculate new tempOut. The calculation of the new tempOUT depends on choice 1 or 2 above.\

( Lookup up the C to F formula online, loop up the F to C formula online )

Print out the the F and the C temps.

Be sure to use the C and F temperature notation ASCII symbol.

Solutions

Expert Solution

If you have any doubts, please give me comment...

import java.util.Scanner;

public class TemperatureConversion {

    public static void main(String[] args) {

        int choice;

        double tempIn, tempOut;

        Scanner scnr = new Scanner(System.in);

        System.out.println("MENU");

        System.out.println("1) Centigrade to Fahrenheit");

        System.out.println("2) Fahrenheit to centigrade.");

        System.out.print("Enter your choice: ");

        choice = scnr.nextInt();

        if (chocie == 1 || choice == 2) {

            System.out.print("Enter temperature value: ");

            tempIn = scnr.nextDouble();

            if (choice == 1) {

                tempOut = (tempIn * 9 / 5.0) + 32;

                System.out.println("C = " + tempIn + "\u00B0, F = " + tempOut + "\u00B0");

            } else {

                tempOut = (tempIn - 32) * 5 / 9.0;

                System.out.println("C = " + tempIn + "\u00B0, F = " + tempOut + "\u00B0");

            }

        } else {

            System.out.println("Invalid choice\n");

        }

    }

}


Related Solutions

Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that is in Fahrenheit for some water. Input the temperature (either an int or a double).   then output one of three statements: if the temperature is below 32 degrees or below tell them it is ice. For example if they input 22 then the output would be: At a temperature of 22 degrees the water would take the form of ice. if the temperature is...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
Answer in JAVA Write a program that would prompt the user to enter an integer. The...
Answer in JAVA Write a program that would prompt the user to enter an integer. The program then would displays a table of squares and cubes from 1 to the value entered by the user. The program should prompt the user to continue if they wish. Name your class NumberPowers.java, add header and sample output as block comments and uploaded it to this link. Use these formulas for calculating squares and cubes are: square = x * x cube =...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a java program that prompt the user to insert last term’s courses and their individual...
Write a java program that prompt the user to insert last term’s courses and their individual mark and store them in an appropriate multidimensional array.
Using Java! Write a program that ask prompt the user to enter a dollar amount as...
Using Java! Write a program that ask prompt the user to enter a dollar amount as double. Then, calculate how many quarters, dimes, nickels and pennies are in the dollar amount. For example: $2.56 = 10 quarters, 1 dime, 1 nickel and 1 cent. Print all of the values. Hint: Use Modulus operator and integer division when necessary.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT