Java

Weather Advice 2

6 points

In this program, you refine the Weather Advice program you wrote previously. In this version, you ask for not only today's high temperature, but also whether it is a weekday or weekend. Assuming that on a weekday you attend school and on a weekend day you don't, you supply advice based on BOTH the high temperature and whether it is the weekend or not.

In the private section of your program, where you list the instance variables of the class, you need to add some variables. Add a Label to ask the user to choose weekday vs. weekend. Add 2 Buttons for the weekday and weekend choices. You may also want to change the positioning of these visual elements.

Inside the method buttonClicked(), set up an IF - ELSE structure.  If the local Button is named 'buttonObj' and the 'weekday' Button is called 'weekDay' the IF statement might start like this:
     if(buttonObj == weekDay)

Inside this IF, start an IF - ELSE IF - ELSE statement.  The purpose of this inner IF structure is to handle the different possible temperatures on this weekday. 

Inside the ELSE branch of the outer IF structure, handle the possibility that the user clicked on the 'weekend' button.  Here you will have another IF - ELSE IF - ELSE structure to handle the different possible temperatures on this weekend day.

 


The GUI layout might look this.

 

Demo

You can download CompletedWeather2.jar to see how your program will run when it is complete.

 

Starting Point

Use your first Weather Advice program as the starting point for the current program.