Question

In: Computer Science

Create a program in java eclipse named “Forecast” and a method called “String getWeather(boolean raining, int...

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.

Solutions

Expert Solution

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


Related Solutions

open up a new Java project on Eclipse named Review and create a new class called...
open up a new Java project on Eclipse named Review and create a new class called Review.java. Copy and paste the below starter code into your file: /** * @author * @author * CIS 36B */ //write your two import statements here public class Review {        public static void main(String[] args) { //don't forget IOException         File infile = new File("scores.txt");         //declare scores array         //Use a for or while loop to read in...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Create a java program that will do the following: Create a method called getInt.Allow the user...
Create a java program that will do the following: Create a method called getInt.Allow the user to enter up to 20 student names,and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns.Use dialog boxes for all input and output.Use the method to input the three scores.Parameter...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the...
In javascript, Add a method named insertStep that receives a String and an int. It adds...
In javascript, Add a method named insertStep that receives a String and an int. It adds the String to the collection of instructions, before the step whose index is the int. You may assume that the user won’t try to insert something before a step that doesn’t exist.
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
Create a complete java program called Week_Report. The program must include two array structures, a string...
Create a complete java program called Week_Report. The program must include two array structures, a string array called DaysOfWeek and a double array called Temp_Values. Store in the DaysOfWeek array the following values (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). Store in the Temp_Values array the following (23.5, 34.0, 20.9, 45.7, 29.3, 34.5, 32.5). Using a for loop structure output the values for the two arrays. Day of the Week Temperature Values Monday 23.5 Tuesday 34.0 Wednesday 20.9 Thursday 45.7...
Create a method:         Public Static boolean isSubArray489(int[] intArray) This method has an array of integers as its...
Create a method:         Public Static boolean isSubArray489(int[] intArray) This method has an array of integers as its input parameter, we'll say that a SubArray 9,8,7is that three integers, 9,8,7values appearing decreasing order one by one in the array. Return true if the array does contain any SubArray “987” Notice that any 3 integers that presenting a decreasing by one order must return True. (987, 876,765,654, 543, 432,321, 210 are all True) Call this method in your main function, and pass in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT