Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383 CSC141 Computer Science I.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
The switch statement Week 5. The switch statement Java Method Coding CONCEPTS COVERED THIS WEEK.
Introduction to Computers and Programming Lecture 6 Professor: Evan Korth New York University.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Boolean Types & Compound Conditionals CSC 1401: Introduction to Programming with Java Lecture 4 – Part 3 Wanda M. Kunkle.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Boolean Expressions Conditional Statements & Expressions CSC 1401: Introduction to Programming with Java Lecture 4 – Part 2 Wanda M. Kunkle.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
The If/Else Statement, Boolean Flags, and Menus Page 180
Chapter 4 Making Decisions
C++ for Engineers and Scientists Third Edition
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 1 st semester King Saud University College of Applied studies and Community Service Csc 1101.
Computer Science Selection Structures.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: An Introduction to Programming Using Visual Basic 2012, All Rights ReservedAn Introduction.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Flow of Control Part 1: Selection
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Decision Making - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 10/27/20151.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
© 2000 Scott S Albert Selection Structures Structured Programming 256 Chapter 4.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 1 st semester King Saud University College of Applied studies and Community Service Csc 1101.
Decisions  Relational operators  Operate on two numbers or two Strings  ==, !=, >, >=,
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
More Selection Executing Statements Selectively Chap. 7 (Read § & Part of Picture: Boolean Logic and Digital Design) 1.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
CCSA 221 Programming in C CHAPTER 6 MAKING DECISIONS 1.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Chapter 5 Selection Statements Mr. Dave Clausen La Cañada High School.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
CSC115: Matlab Special Session Dr. Zhen Jiang Computer Science Department West Chester University.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC530 Data Structures - LOOP 7/9/20161.
More on the Selection Structure
Introduction to C++ Programming Language
Chapter 4: Making Decisions.
Chapter 4: Making Decisions.
CSC115 Introduction to Computer Programming
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Control Structures.
CSC115 Introduction to Computer Programming
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Loop Development Zhen Jiang Dept. of Computer Science
IF if (condition) { Process… }
CSC115 Introduction to Computer Programming
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
CSC530 Data Structure - Decision
Control Structures: Selection Statement
CSC115 Introduction to Computer Programming
Boolean Expressions to Make Comparisons
Zhen Jiang West Chester University
Computer Programming Basics
Control Structures: Selection Statement
Selection Control Structure
Lecture 9: Implementing Complex Logic
Presentation transcript:

Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I

Introduction T/F selection MC selection Selection (Decision)

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

Win/Lost? Yes Double the money Bankrupt No Restart

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

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

Boolean expression in test Simple expression Format 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)

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

Ex 6: 9/4/20159

Development of a correct decision program Grade.java

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! Development Process

Ex 7: Ex 8: 9/4/201513

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

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

Development of a correct multiple- decision program Letter grade

Ex 9

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

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 %, ()?