CS320n –Visual Programming

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Select Case Statements and Selection Input.
Advertisements

Example: Multiple Conditions Execution Control with If Else and Boolean Questions Alice.
CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Parameters and Event-Handler Methods Alice. Mouse input Interactive programs often allow the user to use a mouse to click buttons in a windows-based interface.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Parameters and Event-Handler Methods Sec 50 Web Design.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
Shorter of two objects and changing color Functions, events and setting the color Susan Rodger, Duke University June 2008.
Execution Control with If/Else and Boolean Functions Sec 52 Web Design.
Parameters and Event-Handler Methods Sec 50 Web Design.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.
Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Execution Control with If/Else and Boolean Functions Alice.
CS320n –Visual Programming Introduction to Recursion (Slides 8-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CS320n – Elements of Visual Programming Lists Mike Scott (Slides 9-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CompSci 4 Chap 5 Sec 2 Oct 18, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
CS320n – Elements of Visual Programming Sending Parameters to Event Handler Methods (Slides 5-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
CS320n –Visual Programming Definite / Counted Loops (Slides 7-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
CS320n – Elements of Visual Programming List Search Mike Scott (Slides 9-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Susan Ibach | Technical Evangelist Sage Franch | Technical Evangelist.
Parameters and Event-Handler Methods
Comparing objects and changing color
Execution Control with If/Else and Boolean Functions
EGR 2261 Unit 4 Control Structures I: Selection
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Simple Control Structures
Introduction to Events
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Selection By Ramin && Taimoor
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Lesson 8: Boolean Expressions and "if" Statements
Parameters and Event-Handler Methods
Objectives After studying this chapter, you should be able to:
Items, Group Boxes, Check Boxes & Radio Buttons
Iteration: Beyond the Basic PERFORM
Chapter 4: Decision Structures and Boolean Logic
Conditions and Boolean Expressions
Arrays
Three Special Structures – Case, Do While, and Do Until
Using Functions
Visual Basic – Decision Statements
3.1 Iteration Loops For … To … Next 18/01/2019.
Conditional Logic Presentation Name Course Name
Parameters and Event-Handler Methods
Parameters and Event-Handler Methods
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Chapter 3: Selection Structures: Making Decisions
Selection Statements Chapter 3.
Creating a Simple Game in Scratch
Chapter 4: Decision Structures and Boolean Logic
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
The IF Revisited A few more things Copyright © Curt Hill.
Parameters and Event-Handler Methods
under the direction of Professor Susan Rodger
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Decision Statements.
Presentation transcript:

CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-2) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.

Decision Making in Programs What We Will Do Today Work more with if / else statements using the Zeus lighting bolt world Visual Programming Decision Making in Programs

The Zeus world revisited Recall the Zeus world Testing this world, we found three significant problems Anything the user clicked got zapped by Zeus’ bolt – not just philosophers! Philosophers could get zapped with lightning more than once! if we clicked on Zeus the program halted Visual Programming Decision Making in Programs

Checking One Philosopher Check to see if who is homer add an if / else to the shootBolt method Drag in the who tile then select “==“ and homer == is a relational operator meaning “is equal to” Visual Programming Decision Making in Programs

Decision Making in Programs Logical Operators It is possible to check more than one condition in a boolean statement Visual Programming Decision Making in Programs

Decision Making in Programs Philosophers Only We only want to shoot the bolt when one of the 4 philosopher's is clicked could make 4 separate events like in the fire truck saving people from the burning building OR could check in the shootBolt method if parameter is one of the philosophers if who is a philosopher shoot them else do nothing Visual Programming Decision Making in Programs

Checking Multiple Conditions drag boolean logic, either or to replace condition on if set both values to true initially Visual Programming Decision Making in Programs

Decision Making in Programs changing condition right now the condition is always true change it so it checks if the parameter who is equal to Homer or Plato. Drag who into the condition Visual Programming Decision Making in Programs

Adding More Philosophers If who is equal to plato or homer we will shoot them add in the other philosophers by nesting logical operators Replace trues with a check for who being equal to the other three philosophers Visual Programming Decision Making in Programs

Checking All Four Philosophers long, but does check all 4 philosophers DEMO Visual Programming Decision Making in Programs

Decision Making in Programs Complexity The boolean condition in the if statement that checks to see if who is a philosopher is rather complex someone reading the code may not understand exactly what the purpose of that condition is create a function to check if who is a philosopher make complex things appear simple = abstraction Visual Programming Decision Making in Programs

isPhilosopher function isPhilosopher is still complex but this makes shootBolt look a lot simpler ………… Visual Programming Decision Making in Programs

Decision Making in Programs Demo A demonstration of the Zeus world with If statement and logic operators. What problem have we fixed? If we want to add another person to the scene that Zeus can shoot what changes must be made to the program? What problem still exists? Visual Programming Decision Making in Programs

Completing the Zeus world The second problem is how to prevent lightning striking the same philosopher more than once. How do we know if a philosopher has already been struck by lightning? When a lightning bolt strikes, the philosopher “is zapped” and the his color property is set to black. Checking color is a convenient way to check for a previous lightning strike. Visual Programming Decision Making in Programs

Preventing a duplicate strike We only need to check for a possible duplicate-strike if we already know that a philosopher is clicked the way to handle this is nest a second If statement inside the first != is a relational operator meaning “is not equal to” Visual Programming Decision Making in Programs

Alternative to Nested if Instead of using a nested if we could the logical expression “a and b” as the test for the if a is “the parameter who is a philospher” b is “the parameter who’s color is not black” Visual Programming Decision Making in Programs

Decision Making in Programs Demo A demonstration of completed Zeus world Does it matter if use nested if or a more complex boolean condition? May be easier to use nesting to achieve certain behaviors example, if a philosopher has already been shot, he says “Leave me alone!” Visual Programming Decision Making in Programs