CS1 Homework 2 -- Due Sept. 28, 2005

Name:___________________________

 

1) When is it necessary to have an 'else' statement in an 'if' statement?

2) If it's not raining, we want to go boating.  But if it is raining, and if it's evening, we want to go to the movies.  If it's raining and it's the afternoon, we want to go bowling.  If it's raining and it's any other time of day, we want to stay in bed.  Assume you have true/false values for the booleans 'raining', 'afternoon', and 'evening'.  Also assume you can call methods 'goBoating()', 'goBowling()', 'goMovies()', and 'goSleep()'.  Write the Java code for this decision making.

3) What label in the 'switch' statement is akin to the 'else' statement?

4) Write an 'if' statement to determine a football player's position from his jersey number.  Assume these assignments of numbers to positions:  1-19 quarterback or kicker, 20-49 running back, 50-59 center, 60-79 guard or tackle, 80-89 receivers and tight ends.

5) Write a 'switch' statement to determine a football player's position from his jersey number.  Be sure to include a 'default' case.