Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Some concept of Business Application Programming are Additional Capabilities, Additional Components, Additional Class Features, Control Structures, Input and Formatting, Strings and Characters. Main points of this lecture are: Control Structures, Class Activities, Data Manipulation, Validation and Formatting, Sequence, Selection, Repetition, Rewritten, Structured-Programming Summary, Repetition
Typology: Slides
1 / 85
that
a sequential flow:
Syntax:
if (condition) statement executed if condition is true; else statement executed if condition is false;
if-then-else performs instructions based on
the result of a comparison Place statements on separate lines for readability
Syntax:
if-then-else provides two-way
selection
between executing one of 2 clauses (the if
clause or the else clause)
TRUE (^) FALSE
if clause else clause
condition
if ( Condition )
StatementA
else
StatementB
NOTE: StatementA and StatementB each can be a
single statement, a null statement, or a block.
if ( Condition ) {
} else {
}
The if-
then-else
flowchart.
int carDoors, driverAge ; float premium, monthlyPayment ;
... if ( (carDoors == 4 ) && (driverAge > 24) ) { premium = 650.00 ; System.out.println(“ LOW RISK “ ); } else { premium = 1200.00 ; System.out.println(“ HIGH RISK ”) ; }
monthlyPayment = premium / 12.0 + 5.00 ;
if ( (carDoors == 4 ) && (driverAge > 24) ) premium = 650.00 ; System.out.println(“ LOW RISK “) ; else premium = 1200.00 ; System.out.println(“ HIGH RISK ”) ;
monthlyPayment = premium / 12.0 + 5.00 ;
COMPILE ERROR OCCURS. The “if clause” is the single statement following the if.
if ( lastInitial <= ‘K’ )
volume = 1;
else
volume = 2;
System.out.println(“Look it up in volume # “
AND ( && ): condition is true only if both expressions are true OR ( || ): condition is true if either one or both of the expressions is true NOT (! ): changes an expression to its opposite state; true becomes false, false becomes true
! p NOT p! p is false if p is true ! p is true if p is false
p && q p AND q p && q is true if both p and q are true. It is false otherwise.
p || q p OR q p || q is true if either p or q or both are true. It is false otherwise.
Example:
int age ;
boolean isSenior, hasFever ;
float temperature ;
age = 20;
temperature = 102.0 ;
isSenior = (age >= 55) ; // isSenior is false
hasFever = (temperature > 98.6) ; // hasFever is true
isSenior && hasFever?
isSenior || hasFever?
! isSenior?
! hasFever?
int age, height;
age = 25;
height = 70;
EXPRESSION VALUE
taxRate is over 25% and income is less than $20000
temperature is less than or equal to 75 or humidity is less than
70%
age is over 21 and age is less than 60
age is 21 or 22
WARNING about Expressions in Java
true or false
operands