I need to write a java program that reads the temperature as a whole number from
ID: 3631298 • Letter: I
Question
I need to write a java program that reads the temperature as a whole number from the user and outputs the most likely season based on that temperature.
the parameters for each season are.
110>temperature>= 90 degrees then it is probably summer
90>temperature >= 70 then it is probably spring
70>temperature>=50 then it is probably fall
50>temperature>-5 then it is probably winter
Also if the temperature is more than 110 than the output should be outside the valid range.
Requirements:
The main method will call a method that has one int type parameter. The temperature that the user entered will be passed to the method and based on the temperature passed to the method, the method will return a String that is equal to one of the following:
“spring”, “summer”, “winter”, “fall”, or "out of range"
Also the program must use if/else statements.
Thanks guys for all your help.
I need to write a java program that reads the temperature as a whole number from the user and outputs the most likely season based on that temperature. the parameters for each season are. 110 > temperature > = 90 degrees then it is probably summer 90 > temperature > = 70 then it is probably spring 70 > temperature > =50 then it is probably fall 50 > temperature > - 5 then it is probably winter Also if the temperature is more than 110 than the output should be outside the valid range. Requirements: The main method will call a method that has one int type parameter. The temperature that the user entered will be passed to the method and based on the temperature passed to the method, the method will return a String that is equal to one of the following: spring, summer, winter, fall, or out of range Also the program must use if/else statements.Explanation / Answer
import java.util.Scanner;
public class Temperature {
public static void main(String args[]) {
int temp;
String runAgain;
Scanner input = new Scanner(System.in);
do {
System.out.print("Enter Temperature: ");
temp = input.nextInt();
findSeason(temp);
System.out.print("Enter y or Y to run the program again: ");
runAgain = input.next();
} while (runAgain.equalsIgnoreCase("y"));
}
public static void findSeason(int temp) {
if (temp > 110 )
System.out
.println("The temperature entered is outside the valid range.");
else if (temp >= 90)
System.out.println("It is probably summer.");
else if (temp >= 70 && temp < 90)
System.out.println("It is probably spring.");
else if (temp >= 50 && temp < 70)
System.out.println("It is probably fall.");
else if (temp >= -5 && temp < 50)
System.out.println("It is probably winter.");
}
}