Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming Write a program that reads a temperature as a whole number from

ID: 3922940 • Letter: J

Question

Java Programming

Write a program that reads a temperature as a whole number from the keyboard and outputs a "probably" season (winter, spring, summer, or fall) depending on the temperature.

- If the temperature is greater than or equal to 90, it is probably summer

- If the temp is greater than or equal to 70 and less than 90, it is probably spring

- If the temp is greater than or equal to 50 and less than 70, it is probably fall

- If the temperature is less than 50, it probably winter

- If the temp is greater than 110 or less than -5, then you should out put that the temperature entered is outside the value range.

Explanation / Answer

/**
* The java program TempDriver that prompts user
* to enter temperature in fahrenheit and
* checks if temperature is in a range of -5
* and 110 and prints the season.
* */
//TempDriver.java
import java.util.Scanner;
public class TempDriver {

   public static void main(String[] args) {

       //Create an instance of Scanner class
       Scanner scanner=new Scanner(System.in);
       //delcare an integer variable
       int tempInFahrenheit;

       //repeat until enters an valid temperature
       do
       {
           System.out.println("Enter temperature (in fahrenheit)");
           tempInFahrenheit=scanner.nextInt();

           if(tempInFahrenheit<-5 || tempInFahrenheit>110)
               System.out.println("Error: Temperature is out of range.");

       }while(tempInFahrenheit<-5 || tempInFahrenheit>110);

       System.out.print("probably ");

       //print season
       if(tempInFahrenheit>=90)
           System.out.println("summer");
       else if(tempInFahrenheit>=70 && tempInFahrenheit<90)
           System.out.println("spring");
       else if(tempInFahrenheit>=50 && tempInFahrenheit<70)
           System.out.println("fall");
       else
           System.out.println("winter");

   }//end of main
}//end of the class


--------------------------------------------------------------------------------------------------------------------------------

Output:

Enter temperature (in fahrenheit)
-10
Error: Temperature is out of range.
Enter temperature (in fahrenheit)
90
probably summer

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote