Announcements%20 - PowerPoint PPT Presentation

About This Presentation
Title:

Announcements%20

Description:

... Basic Elements and Conditionals. Announcements & Review. Announcements. Discussion Sections PAI 5.70, quiz excercise, problem available at 9am, due 10pm Tuesday ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 17
Provided by: CSCF
Category:

less

Transcript and Presenter's Notes

Title: Announcements%20


1
Announcements 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

2
Today
  • More basic program elements
  • Types
  • Variables
  • Operators
  • Conditional execution
  • if (condition)
  • // true action
  • else
  • // false action

3
Programming 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

4
Operators, 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

5
Some 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

6
BlueJ Examples

7
A 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 !

8
Defining boolean variables
  • Local boolean variables are uninitialized by
    default
  • boolean isWhitespace
  • boolean receivedAcknowledgement
  • boolean haveFoundMissingLink

-
isWhitespace
-
receivedAcknowledgement
-
haveFoundMissingLink
9
Defining boolean variables
  • Local boolean variables with initialization
  • boolean canProceed true
  • boolean preferCyan false
  • boolean completedSecretMission true

true
canProceed
false
preferCyan
true
completedSecretMission
10
Truth 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

11
And, Or, Not truth tables
p not p
False True True False
12
Boolean algebra
  • Can create complex logical expressions by
    combining simple logical expressions
  • not (p and q)

13
DeMorgans 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
14
Conditionals
  • 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?)
15
BlueJ Examples

16
More Questions?
Write a Comment
User Comments (0)
About PowerShow.com