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

Write a program that reads a temperature as a whole number from the keyboard and

ID: 3697981 • Letter: W

Question

Write a program that reads a temperature as a whole number from the keyboard and outputs a “probable” 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 temperature is greater than or equal to 70 and less than 90, it is probably spring. •If the temperature is greater than or equal to 50 and less than 70, it is probably fall. •If the temperature is less than 50, it is probably winter. •If the temperature is greater than 110 or less than -5, then you should output that the temperature entered is outside the valid range.

Explanation / Answer

package assignment;

import java.util.Scanner;

public class TemperatureSeasonTest {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);

       double temp = 0;
       String cont = "yes";
       while (!cont.equalsIgnoreCase("no")) {
           do {
               System.out.println("Please Enter temperature ( -5 to 110): ");
               temp = sc.nextDouble();
               if (temp < -5 || temp > 110) {
                   System.out.println("Invalid temperature");
               } else {
                   System.out.print("Probable season: ");
                   if (temp >= 90)
                       System.out.println("summer");
                   else if (temp >= 70 && temp < 90)
                       System.out.println("spring");
                   else if (temp >= 50 && temp < 70)
                       System.out.println("fall");
                   else if (temp < 50)
                       System.out.println("winter");

               }
           } while (temp < -5 || temp > 110);
          
           System.out.println("Do you want to continue(yes/no): ");
           cont = sc.next();
           if(cont.equalsIgnoreCase("no"))
               break;
       }
   }
}


---outut------------------

Please Enter temperature ( -5 to 110):
8
Probable season: winter
Do you want to continue(yes/no):
yes
Please Enter temperature ( -5 to 110):
10
Probable season: winter
Do you want to continue(yes/no):
no

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