Conditional Statements
February 17th, 2016
Produced During Lecture
Important Concepts from the Reading
- conditional statements: if, if else, else-if, switch
- arithmetic comparison operators: ==, !=, <, ≤, >, ≥
- boolean operators: !, &&, ||
Lecture Problem
Write a program that creates two cards (e.g. an "Ace" of "Spades" and a
"Seven" of "Clubs") and then determines whether
the dealer must "Hit" or "Stand". A dealer will "Hit" if the initial
two cards either (1) total 16 or less or (2) make a soft 17.
Otherwise, the dealer will "Stand".
Use Driver.java as a starting point.
Take-home Exercise
- Review the sample code (ConditionalExample.java). Make
sure you understand each one.
- Make up some conditional statements of your own based on age
(legal drinking age, too old to be trick-or-treating, need a
full priced pass at Bridger Bowl).
- Try to make some compound statements based on age windows
using && or ||.
- Create a new parameter such as double income, or String
occupation and make some conditional statements based on that.
Can you make statements with both your new parameter and age?
(If your are less than or equal to 30, and your assets are over
$30 billion, you must be Mark Zuckerberg)