### Lab

Remember to review questions starting on p. 268.

### Chapter 4 Decision Structures: Vocabulary

 Types of Decision Structures:   ... if statement   ... if-else statement   ... multi-way if-else   ... nested if-else   ... switch statements   ... indentation conventions Code blocks & variable scope Decision Structure Syntax:   ... decision logic and flow charts   ... condition and body   ... boolean value, expression Random numbers Building Boolean Expressions:   ... relational operator (<, >, <=, >=, ==, !=)   ... boolean (logical) operators (!, &&, ||)   ... boolean operators precedence (See table)   ... truth tables (e.g. Tables 4-6,4-7,4-8)   ... De Morgan's Laws String Comparison   ... Lexicographic ordering (of Strings)   ... compareTo() and .equals operators Other (optional)   ... The Conditional Operator bool ? val1 : val2   ... Switch statement (p. 238)   ... DecimalFormat (p. 248)

### Topics:

• Medical example pseudo code - What to do if you have a fever or not.
• If-statement, if-else
• Syntax
• Code Blocks & Scope - Braces & indentation
• Boolean values and variables:
• What is a boolean variable? (boolean, true/false)
• Relational operators - making number comparisons with `<, >, <=. >=, ==, != `
• Be careful!! Equality of Strings. Do not use ` ==`. Instead, use myString1.equals(myString2)
• Adding Complexity: Multi-way, nested if-else
• Branch, branching, flow charts
• Boolean operators &&, ||, ! Watch precedence. Write out truth tables.
• Combining with relational operators
• Strings and lexicographic ordering - compareTo operator
• Rules of Thumb & Common Errors:
• Avoid duplication in branches
• Dangling else problem
• Syntax for condition ( 5 < x < 7 ) is NOT allowed! Need to use boolean operators.
• De Morgan's Law:
• !(A && B) same as (!A) || (!B)
• !(A || B) same as (!A) && (!B)
• Input validation (will work better after we do loops in chapter 4)
• Less Commonly used structures:
• Conditional Operator :
• condition ? value1 : value2;
• Example: `int bigger = (x>y) ? x : y ;`
• Switch statement: switch (digit) { case a: break; ...default: ... }
where digit can be byte, short, int, char, enumerated types (discussed in later chapter), and (recently) Strings
• See list of common errors on p. 267 of your text.