Lecture 9, CS 302-7 and 8, February 10
i. Due Feb 24
ii.
Partners Feb
17
iii.
Piazza
i. Multiple alternatives and nested conditions
i. boolean <name> = <true or false>;
i. And, Or, Not
i. A and B are conditions
1.
eg
x>5, y==4
ii.
A&&B,
A ||B, !A
i.
A || B
&& !C -> A || (B && (!C))
ii. Rule of thumb: When in doubt, use ()
i. Simplifications
1.
!(x=y)
-> x!=y
2.
!
(x>y) -> x<=y
ii. DeMorgan’s law
1.
!(A
&& B)=>!A || !B
2.
!(A || B)
=>!A && !B
iii. Lazy evaluation
1. example - if(quantity>0 && price/quantity)
2. Once first half is false, does not need to compute second half
3. Once common use is to avoid /0 errors, like in above
i. hasNextInt
ii. hasNextDouble
iii. hasNext
iv. hasNextLine
i. Condition can be either explicit or implicit boolean