mit app inventor lesson 4 – decision making. agenda comparisons ◦ relational operators...
Post on 17-Jan-2016
226 Views
Preview:
TRANSCRIPT
MIT App Inventor
Lesson 4 – Decision Making
AgendaComparisons
◦Relational Operators
Conditions (state checking)◦Boolean Operators
Motivation
People make decisions often.
Programs need information and conditions to make decisions.
How do we make decisions?
We Use Information
Qualitative Quantitative
Raining? 5 degrees Celsius
Type of Information
Feature Quantity
Quantitative Decisions?
ScenarioCompare values to help determine which code to execute next within the program.
CS ConceptRelational Operators
◦ Used to compare values (operands)
AI – Relational Operators
LocationMath block group
Example.When a student obtains a mark between 50% and 100% (inclusive) they will be granted a credit for the course.
AI – Relational OperatorsLocated within the Math block group
Operator Comparison Description
Greater than
Greater than or Equal to
Less than
Less than or Equal to
Equal to
Not Equal to
Relational Operator Examples
Controlling Program Flow
How can a user control program flow?
◦Buttons
Controlling Program Flow
How can a programmer control program flow?
◦Order of block/code in the design (blocks editor) will determine the order of execution Sequential – Top to bottom in order
◦Others? Procedures – Named group of blocks /
Called by the programmer
Programming FundamentalsSoftware programs consist of 3 key components:
◦Data Structures Variables – named storage areas (more later)
◦Control Structures Decision making (this lesson)
◦Algorithms combinations of Data and Control Structures
to solve a specific well-defined program
Take Control with Control StructuresLocated within the Control block group
Conditional Block◦condition (test)◦set of statements to
be executed when the condition is true.
Simple Condition - ExampleScenario involves checking one criteria and there is only an unique action to be taken if the criteria is met (otherwise true).
Example: Voting Condition
Handling Two Outcomes
ScenarioSingle Criteria with two Outcomes
Problem DomainCompleting your in-car driving test with a goal of obtaining your drivers license.
Only 2 possible outcomes1. Pass2. Fail
Getting Your License
Qualitative Decisions?
ScenarioCheck states to help determine which code to execute next within the program.
CS ConceptBoolean Operators
◦ Used to compare states (operands)
Boolean Operators
Any question that can be answered
Yes or No is considered a boolean condition.
Interesting FactBoolean logic was initially described by George Boole (1815-1864). This was long before the existence of the first digital computers.
Example: Boolean and Relational
Example.If it is raining outside and it is between 5C and 10 C I will wear my warm rain jacket and take the bus.
Multiple conditions must be met.
AI – Boolean OperatorsLocated within the Math block group
Operator Comparison DescriptionAll tests must be true for result to be true
If any of the tests are true the result is true.
The result is the opposite of the input.
Complex Example
Lab 4 – Temp ConvertorObjectiveCreate a temperature convertor program for Fahrenheit and Celsius.
◦ Components Button TextBox Screen Arrangement
◦ Concepts Math operators Conditions
If test then-do
Ifelse test then-do else-do
◦ Algorithms see lab instructions
Example from the next Lab
top related