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

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...
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.
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.
1. Write a program that analyzes savings and expenses (variables of type double). Prompt the user...
1. Write a program that analyzes savings and expenses (variables of type double). Prompt the user for and retrieve these two values that have been given values. The program outputs the word Solvent, decreases the value of savings by the value of expenses, and sets the value of expenses to zero if the savings is at least as large as expenses. If, however, savings is less than expenses, the program simply outputs the word Bankrupt and does not change the...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for...
jgrasp environment, java write a complete program that calculates a restaurant bill. Prompt the user for the check amount, then ask the user what type of tipp they would like to leave: the choices are 1 for good tip (20%), 2 for an average tip (15%), or 3 for poor tip (10%). Use their input and an if-else to calculate the tip amount. Then calculate and output the final bill: check+tip print out the bill, exactly as shown (print the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT