Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods.

Slides:



Advertisements
Similar presentations
The IF function Bernard Liengme. Objectives To know how to: Construct a condition using the comparison operators =, >=, >, ; Construct a formula using.
Advertisements

© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement  Conditional control structure, also called a decision structure  Executes a set of statements.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
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.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2009ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Fall 2009ACS-3913 Ron McFadyen Composite Pattern Problem: How do we treat a composition structure of objects the same way as a non-composite object? Arises.
If Statements & Relational Operators Programming.
Fall 2009ACS-1805 Ron McFadyen1 Functions A function is a collection of statement, similar to a method, but a function is defined to return a value to.
A Quick Look at Quantified Statements. Why are Quantified Statements Important? The logical structure of quantified statements provides a basis for the.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Fall 2007ACS-1805 Ron McFadyen1 Functions and if-else A function is a collection of statement, similar to a method, but a function is defined to return.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
Fall 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
1 Fall 2008ACS-1805 Techniques for designing code Storyboards Text (aka pseudocode) Diagrams Flowcharts (a procedural technique) Text presents one of these.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 7 Repetition.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
Assignment 2 Sample problems. Consider the following expression: ((False and not True) or False or (True and not True)) True False.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 3 Programming - Putting Together the Pieces.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 8 Recursion.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 6 Functions & If/Else.
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
1 CSE 20: Lecture 7 Boolean Algebra CK Cheng 4/21/2011.
As you come in…  DOWNLOADS FOR TODAY:  CarGameTeacherStarter.a2w  Online student textbook.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
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.
An Introduction to Programming Using Alice Boolean Logic.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Flow of Control Part 1: Selection
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Functions Alice.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
Inequalities Section 10.2 Solving Inequalities. Property of Comparison For all real numbers a and b, one and only one of the following must be true: a
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
Conditional Statements © Copyright 2014, Fred McClurg All Rights Reserved.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Boolean Logic in Programming. Boolean Logic Branching and looping routines both contain conditions that are either true or false. In 1854 George Boole.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Variables & Conditions.
Laws of Boolean Algebra Commutative Law Associative Law Distributive Law Identity Law De Morgan's Theorem.
Boolean Algebra Boolean Assertions Statements that will result in true or false outcomes a > 50 = = ba
Control statements Mostafa Abdallah
booleans hold a true/false value We take advantage of this by using them to decide which route our program will take. Examples: stinky holds the boolean.
Conditional Control Structures Chapter 5. Goals and Objectives Understand conditional control structures. Demonstrate the use of decision structures to.
Properties Objective: To use the properties of numbers. Do Now 1.) = 3.) ( 2  1 )  4 = 2.) =4.) 2  ( 1  4 ) =
Fall 2008ACS-1805 Ron McFadyen1 Event-driven programming Chapter 5 covers event-driven programming. Events are user or condition driven and so each event.
TestScore < 80 testScore * 2 >= < w / (h * h) x + y != 2 * (a + b) 2 * Math.PI * radius
CONTROL STRUCTURES (SELECTION). PROGRAM COMPONENTS  SEQUENCE  Groups Of Sequential Steps  SELECTION  Making Choices  IF-THEN (one way)  IF-THEN-ELSE.
Warm Up Week 6 1) write an equation that passes through the given point and y-intercept. ( 2, 1 ) ; b = 5.
Conditional Control Structures Chapter 5 Review. The If Statement The if statement is a conditional control structure, also called a decision structure,
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
If statement.
2-1 Making Decisions Sample assignment statements
Boolean Algebra.
Conditional Logic Presentation Name Course Name
Find the reference angle for the angle measuring {image}
Expressions.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Relational Expressions
Event-driven programming
Conditionals.
Presentation transcript:

Fall 2007ACS-1805 Ron McFadyen1 Boolean functions & expressions A boolean function is one that returns true or false The guidelines for class-level methods also apply to class- level functions: No references to other objects. No references to world-level functions you have written, but built-in world-level functions are fine to use

Fall 2007ACS-1805 Ron McFadyen2 Boolean expressions Expressions like a==b test two operands and return a value of true or false. Boolean expressions are used in while, if expressions, … A boolean function has returns like: Boolean operators not, and, or can be expressed in tabular form a!=b means “a not equal to b”

Fall 2007ACS-1805 Ron McFadyen3 Boolean expressions These are simple boolean expressions that are either true of false What is the phrase: possiblePhilosopher = who ?

Fall 2007ACS-1805 Ron McFadyen4 Boolean expressions Not operator anot a truefalse true

Fall 2007ACS-1805 Ron McFadyen5 Boolean expressions And operator ba and b true false a true false

Fall 2007ACS-1805 Ron McFadyen6 Boolean expressions Or operator ba or b true falsetrue a false … In alice, we compose boolean expressions that are of a nested form:

Fall 2007ACS-1805 Ron McFadyen7 Boolean expressions The text has a couple of examples on page 167: 1. either (both(who==homer) and (who.color==blue)) or (who.color==black) or both Consider: And then we develop: How is this interpreted, how is it developed?

Fall 2007ACS-1805 Ron McFadyen8 Boolean expressions The text has a couple of examples on page 167: 2. both(who==homer) and (either who.color==blue or who.color==black or both) Consider: And then we develop: How is this interpreted, how is it developed?

Fall 2007ACS-1805 Ron McFadyen9 Boolean expressions The text has a couple of examples on page 167: 1. either (both(who==homer) and (who.color==blue)) or (who.color==black) or both 2. both(who==homer) and (either who.color==blue or who.color==black or both) Are they the same? Are they different?

Fall 2007ACS-1805 Ron McFadyen10 Ch6 ends with Random Functions There are two random functions in alice: 1.Choose true …. Returns a boolean value 2.Random number Returns a number as you prescribe