ITEC 120: Week 9
- Tuesday:
- conditions to graduate and not graduate
- two ifs vs if else
- remembering a boolean result
- definite assignment
- statement blocks
- examples from book
- Thursday:
- Nested vs sequential if statements
- if else if else if else (eg grades)
- Equality of objects
- == compares references
- default version of .equals compares references
- specialized version of .equals compares fields
- Equality of Strings
- Use .equals
- == compares references (but strings can share references)
- Switch statements
- Similar to if else if else if else
- Use break
- Coding if else if else
- Examples: ...
- Chapter 5: Logical operators, if-else, block statements
- Logical operators combine two boolean values and produce another boolean value
- Contrast with
- Arithmetic operators combine 2 numbers and produce another number
- Relational operators compare two numeric values and produce another number
- Logical operator AND (ie &&)
- Result is true if both operands are true, false if either or both are false
- Truth table
- Example: graduation requirements: hours and gpa
- Logical operator OR (ie ||)
- Result is true if either operand is true, false if both are false
- Truth table
- Example: major and concentrations
- Logical operator NOT (ie !)
- Operates on a SINGLE value
- Unary operator vs binary operator (eg -3 + 4 shows both)
- Result is true if operand is false, and false if operand is true
- AKA logical negation and logical complement (not compliment)
- Truth table
- && and || are SHORT CIRCUIT operators: only evaluate second operand when required
- Example: if (x != 0 && 3/x > 5)
- DeMorgan's Law: !(a && b) == (!a || !b)
- DeMorgan's Law: !(a || b) == (!a && !b)
- if-else:
- Use else to nest two statements
- execute then part when condition is true
- execute else part when condition is false
- Examples:
- helps with definite assignment
- Block statements
- A block statement is one or more statements enclosed in curly braces
- Makes it possible to use several statements where one is required
- Can be used as then and/or else parts
- Guessing.java
- Careful of indentation of multiline then or else parts
- Lab
14
- Lab 15
- Examples from Chapter 5
- Chapter 5 Powerpoint Slides
- Semester
Calendar