Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC530 Data Structure - Decision

Similar presentations


Presentation on theme: "CSC530 Data Structure - Decision"— Presentation transcript:

1 CSC530 Data Structure - Decision
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383

2 Selection (Decision) Introduction T/F selection MC selection

3 Selection (Decision) Rolling a dice.
Sample execution (click on this link to try) Each button in the above sample has

4 No Yes Win/Lost? Double the money Bankrupt Restart

5 If else statement if (test) action 1 (statements 1) else action 2 (statements 2) //end if action 3 (statement 3)

6 No Yes Test by boolean expression Action 1 Action 2 Action 3

7 Boolean expression in test
Simple expression Format <Value> <relational operators> <Value> Number value relational operators ==, !=, <, >, <=, >= !!! Number one error: “(a=2)” instead of “(a==2)” char value (not string!) relational operators ==, !=

8 Complex expression &&, ||, ! Truth table Precedence order Number range

9 Development of a correct decision program
Grade.java

10 Development Process Identify two exclusive options
Implement each handling in different action parts Identify the situation (values) for option selection Make an expression so that all the situation value for option part 1 will lead to the test result (boolean value) true. Verify all the situation value for option part 2 will lead to the test false, otherwise, revise the above expression!

11 If statement Relational operator ? Multiple selection
Nested if If else if Example: letter grade

12 Comments: Nested if for multiple selection problem If case 1 else if
//end of case 2 if //End of case 1 if

13 Development of a correct multiple-decision program
Letter grade

14

15 Switch Switch([variable]) Case [constant value]: Break (or no break)


Download ppt "CSC530 Data Structure - Decision"

Similar presentations


Ads by Google