In: Computer Science
Create a program in java eclipse named “Forecast” and a method called “String getWeather(boolean raining, int temperature)”. Depending on the parameters, return one of four outcomes:
If it’s not raining and under 30 degrees: return “The weather is chilly”
If it’s not raining and at/over 30 degrees: return “The weather is sunny”
If it’s raining and under 30 degrees: return “The weather is snowy”
If it’s raining and at/over 30 degrees: “The weather is rainy”
You must use nested if statements for this problem.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Forecast.java
import java.util.Scanner;
public class Forecast {
public static void main(String[] args) {
int temp;
boolean rain;
/*
* Creating an Scanner class
object which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
//Getting the input
entered by the user
System.out.print("Enter temperature :");
temp=sc.nextInt();
System.out.print("Is it raining :");
rain=sc.nextBoolean();
String mesg=getWeather(rain,temp);
System.out.println(mesg);
}
private static String getWeather(boolean rain, int
temp) {
String mesg="";
if(!rain &&
temp<30)
mesg="The
weather is chilly";
else if(!rain
&& temp>=30)
mesg= "The weather is sunny";
else if(rain
&& temp<30)
mesg="The weather is snowy";
else if(rain
&& temp>=30)
mesg="The weather is rainy";
return mesg;
}
}
_______________________
Output#1:
Enter temperature :40
Is it raining :false
The weather is sunny
_______________________
Output#2:
Enter temperature :24
Is it raining :true
The weather is snowy
_______________Could you plz rate me well.Thank You