Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am in college and these are the topics that we have already covered:
- basic java syntax - keywords
- data types - variables
- typecasting and parsing - operators
- Scanner - control statements
Write a program that will continuously allow the user to enter the following:

Temperature at 3 different instances
Unit of Temperature for the 3 inputs (Celsius, Fahrenheit, Kelvin)
Unit of Temperature for Conversion (Celsius, Fahrenheit, Kelvin)
Once all these details have been entered get the average of the 3 temperatures and if they are divisible by 2 then:

Output the average temperature
Convert it to the chosen unit of measurement of their 3rd input
Notify the user if it is above or below room temperature for that unit of measurement (Note: 20°C is the average room temp. Also besides the room temp in celsius the values for room temp in other unit of measurements cannot be stored in a variable but instead the value in celsius must be converted into the chosen unit in the 3rd input)
If the average of the 3 temperatures are divisible by 3 then:

Convert the 3 temperatures individually to the chosen unit of measurement of their 3rd input
Then similar to the condition above check if each temp is above or below room temperature and output them each
If none of these conditions are met or the output has been printed then it will return to ask the user to enter new values.

If at any point during the input stage the user enters the word "Quit" then end the program.
Example output:
Average Temperature: 19 degrees celsius
Note: Below Room Temperature
We are expected to solve this using only what we have covered.

What I have tried:

We just received a hint that a loop is used and the loop only ends if "Quit" is entered.
also the Scanner is inside the loop. So while (userinput != "yes") at the very beginning? I don't know how to go about doing it.
package Main;
Java
import java.util.Scanner;
public class TemperatureCheck {
   public static void main(String[] args) {
       System.out.println("Give three values of a temperature unit.");
       Scanner sc = new Scanner(System.in);
       int temp1 = sc.nextInt();
       int temp2 = sc.nextInt();
       int temp3 = sc.nextInt(); //the temperature at 3 instances.
       System.out.println(temp1);
       System.out.println(temp2);
       System.out.println(temp3);
       System.out.println("Which unit of temperature is it?"); //unit of temperature for the 3 inputs.
       String tempUnit = sc.next();
     System.out.println("Give a unit of temperature to convert it into."); //Unit of Temperature for Conversion
     String tempTOConvertInto = sc.next();
     int avgTemperature = temp1 + temp2 + temp3;
     if (avgTemperature % 2 == 0) {
         System.out.println(avgTemperature);
         //Convert it to the chosen unit of measurement of their 3rd input
Posted
Updated 16-Sep-22 4:51am
v2

1 solution

See here: Java While Loop[^] - check out the do ... while loop - it has teh test at the end, rather than the beginning of the loop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900