+ All Categories
Home > Documents > MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators...

MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators...

Date post: 17-Jan-2016
Category:
Upload: sabrina-willis
View: 224 times
Download: 0 times
Share this document with a friend
Popular Tags:
22
MIT App Inventor Lesson 4 – Decision Making
Transcript
Page 1: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

MIT App Inventor

Lesson 4 – Decision Making

Page 2: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

AgendaComparisons

◦Relational Operators

Conditions (state checking)◦Boolean Operators

Page 3: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Motivation

People make decisions often.

Programs need information and conditions to make decisions.

Page 4: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

How do we make decisions?

We Use Information

Qualitative Quantitative

Raining? 5 degrees Celsius

Type of Information

Feature Quantity

Page 5: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Quantitative Decisions?

ScenarioCompare values to help determine which code to execute next within the program.

CS ConceptRelational Operators

◦ Used to compare values (operands)

Page 6: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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.

Page 7: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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

Page 8: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Relational Operator Examples

Page 9: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Controlling Program Flow

How can a user control program flow?

◦Buttons

Page 10: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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

Page 11: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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

Page 12: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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.

Page 13: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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

Page 14: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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

Page 15: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Getting Your License

Page 16: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Qualitative Decisions?

ScenarioCheck states to help determine which code to execute next within the program.

CS ConceptBoolean Operators

◦ Used to compare states (operands)

Page 17: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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.

Page 18: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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.

Page 19: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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.

Page 20: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Complex Example

Page 21: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

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

Page 22: MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Example from the next Lab


Recommended