Title: Announcements%20
1Announcements Review
- Last Time
- Beauty
- Repetition
- for - the iterated loop in Java
- Announcements
- Discussion Sections PAI 5.70, quiz excercise,
problem available at 9am, due 10pm Tuesday - Reading Ch 1-4, Regis and Stepp on-line
- Lab 1 Due Thursday 10pm
2Today
- More basic program elements
- Types
- Variables
- Operators
- Conditional execution
- if (condition)
- // true action
- else
- // false action
-
3Programming Elements
- Type
- Set of values and operators that create and
manipulate values from the set - Values primitive types
- numeric
- double and float (size)
- Values with decimals
- int, byte, short, long (size)
- Integers
- Character char
- Characters (considered numeric)
- Boolean boolean
- Logical values
4Operators, Constants, Variables
- Basic operators
- addition - subtraction
- multiplication / division
- Constant
- Symbolic name for memory location whose value
does not change - final int MAX_HEART_RATE 220
- Variable
- Symbolic name for memory location whose value can
change - int age
5Some declarations operations
- // Computes target heart rate
- // final means the program can never change it
- final int MAX_HEART_RATE 220
- int age 18
-
- // target heart rates
- int aerobicZone, fatBurningZone
- aerobicZone MAX_HEART_RATE - age .75
- fatBurningZone MAX_HEART_RATE - age .65
6BlueJ Examples
7A boolean type
- Java has the logical type boolean
- Type boolean has two literal constants
- true
- false
- Operators
- The and operator is
- The or operator is
- The not operator is !
8Defining boolean variables
- Local boolean variables are uninitialized by
default - boolean isWhitespace
- boolean receivedAcknowledgement
- boolean haveFoundMissingLink
-
isWhitespace
-
receivedAcknowledgement
-
haveFoundMissingLink
9Defining boolean variables
- Local boolean variables with initialization
- boolean canProceed true
- boolean preferCyan false
- boolean completedSecretMission true
true
canProceed
false
preferCyan
true
completedSecretMission
10Truth tables
- formal specifications of operators
- It works as most of us would expect allows for
ambiguity of interpretation - Jim is smiling or Patty is smiling
- Can both Jim and Patty be smiling?
- Truth tables
- Lists all combinations of operand values and the
result of the operation for each combination
11And, Or, Not truth tables
p not p
False True True False
12Boolean algebra
- Can create complex logical expressions by
combining simple logical expressions - not (p and q)
13DeMorgans laws
- not (p and q) equals (not p) or (not q)
not (not p) or p q p and q (p
and q) ( not p) (not q) ( not q)
False False False True True
True True False True False True
True False True True False
False True False True
True True True True False False
False False
14Conditionals
- Conditional expression must evaluate to the
boolean value true - int x, y // compute max
- if (x gt y)
- max x
- else // x lt y
- max y
-
boolean next false if (next)
...println(May I help you?)
15BlueJ Examples
16More Questions?