Subgoals for Writing Selection Statements
Define how many mutually exclusive paths are needed
Order from most restrictive/selective group to least restrictive
Write if statement with Boolean expression
Follow with true bracket including action
Follow with else bracket
Repeat until all groups and actions are accounted for
OR Switch Statement
Determine variable / expression for mutually exclusive ranges
Write switch statement based on variable / expression
Each range is a ‘case’
Include break statements and default case if needed
Put the code in the right order to create a program that will generate an integer value between 0 and 25, print the value, and if the value is greater than 18, print a message saying “This is an overload”; otherwise print a message saying “Not an overload”.
Put the code in the right order to create a program that will generate an integer value between 3 and 7, print the value, and if the value is equal to 5 then set the character variable classType equal to ‘G’, and print a message saying “graduate student”; otherwise set classType equal to ‘U’ and print a message saying “undergraduate”.
Put the code in the right order to create a program that will generate the value for a year (1500 to 3000 inclusive) and print the value. Then it will print true if the year is a leap year, otherwise the program prints false. A leap year is a multiple of 4, with one exception: if the year is a multiple of 100 but not 400, then it is not a leap year. For example, the year 1900 was not a leap year, but the year 2000 was indeed a leap year.