1 / 19

Selection and Decision Making in Computer Science

Learn about selection and decision making in computer science, including conditional statements, boolean expressions, and complex decision-making processes. Develop correct decision-making programs using if statements, multiple selection, and the switch statement.

sangw
Télécharger la présentation

Selection and Decision Making in Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC141 Computer Science I Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383 zjiang@wcupa.edu

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

  3. Selection (Decision) • Rolling a dice. • Sample execution (click on this link to try • http://www.cis.temple.edu/~jiang/dice.exe • 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, Table 3-1, page 111 ==, !=, <, >, <=, >= !!! Number one error: “(a=2)” instead of “(a==2)” • char value (not string!) relational operators ==, != (page 118)

  8. Complex expression • &&, ||, ! (Table 3-4, page 135) • Truth table • Table 3-6, page 136 • Table 3-7, page 139 • Table 3-8, page 141 • Precedence order, table 3-10, page 142 • Number range, page 142-143

  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. 60, 61, 62, …, 100 ? 1, 2, …, 58, 59

  12. Exercises 6 and 7, development of a correct decision program

  13. If statement, Code 3-1, page 113 • Relational operator ?, page 151 • Multiple selection • Nested if, Code 3-4, page 127 • If else if, Code 3-5, page 131 • Example: letter grade

  14. Comments: • Nested if for multiple selection problem If case 1 Else if case 2 else … //end of case 2 if //End of case 1 if

  15. Development of a correct multiple-decision program • Letter grade

  16. Exercise 8

  17. Switch • Switch([variable]) • Case [constant value]: • Break (or no break), Code 3-13, 3-14, page 155-157

  18. Project 2 • 11 case • If-else • BMI expression simplification • Last else no if • Nested if and multiple if • Avg < 90 && test1 < 90 to attend the final • Discount • %, ()?

More Related