0% found this document useful (0 votes)
285 views

#5 Java Conditional Statements - MIDTERM

The document discusses Java OOP conditional statements. It covers topics like if, if-else, if-else if-else statements and relational, logical operators. Examples are provided to demonstrate how to use conditional statements to check conditions and execute code blocks accordingly. The last part provides an activity to create a grade average program that takes user input for 4 grades, calculates the average and displays a message based on qualification criteria.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
285 views

#5 Java Conditional Statements - MIDTERM

The document discusses Java OOP conditional statements. It covers topics like if, if-else, if-else if-else statements and relational, logical operators. Examples are provided to demonstrate how to use conditional statements to check conditions and execute code blocks accordingly. The last part provides an activity to create a grade average program that takes user input for 4 grades, calculates the average and displays a message based on qualification criteria.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Click to edit Master title style

Java OOP – Conditional


Statements

1
Lesson Topics
Click to edit Master title style

1. Conditional Statements
2. Relational Operators
3. If Statements
4. If – Else Statements
5. If – Else If – Else Statements
6. Nested Conditional Statements
7. Equals Function
8. Logical Operators
9. Lesson Activity 2 2
CONDITIONAL STATEMENTS
Click to edit Master title style

Allows a program to take action base on the


given Condition.
It makes our program smarter.

3 3
CONDITIONAL STATEMENTS
Click to edit Master title style

Typically, it compares two values so that our


program can decide what action should be
taken.

4 4
RELATIONAL OPERATORS
Click to edit Master title style

LABEL SYMBOL SYNTAX


Equal to == x == y
Not Equal to != x != y
Less than < x<y
Less than or equal to <= x <= y
Greater than > x>y
Greater than or equal to >= x >= y

5 5
IF STATEMENT
Click to edit Master title style

Handles 1 Conditional Expression, It either


does Something or Nothing.

6 6
IF STATEMENT
Click to edit Master title style

If (condition){
// Do something here
}

7 7
IF STATEMENT
Click to edit Master title style

If (age >= 18){


System.out.println(“You have access!”);
}

8 8
Click to edit Master title style

9 9
Click to edit Master title style

10 10
RELATIONAL OPERATORS
Click to edit Master title style

LABEL SYMBOL SYNTAX


Equal to == x == y
Not Equal to != x != y
Less than < x<y
Less than or equal to <= x <= y
Greater than > x>y
Greater than or equal to >= x >= y

11 11
Click to edit Master title style

12 12
IF ELSE STATEMENT
Click to edit Master title style

Handles 2 Conditional Expressions, It either


does the first Code block or the second Code
block.

13 13
IF ELSE STATEMENT
Click to edit Master title style

If (condition){
// Do something here
}
else{
// Do something here
}
14 14
IF ELSE STATEMENT
Click to edit Master title style

If (age >= 18){


System.out.println(“You have access!”);
}
else{
System.out.println(“Access Denied!”);
}
15 15
Click to edit Master title style

16 16
Click to edit Master title style

17 17
IF, ELSE IF, ELSE STATEMENT
Click to edit Master title style

Handles 3 or more Conditional


Expressions, the possibility of this statements
are limitless it will run a certain code block
based on the condition.

18 18
IF, ELSE IF, ELSE STATEMENT
Click to edit Master title style

If (condition){
// Do something here
}
else if(condition){
// Do something here
}
else{
// Do something here
}
19 19
IF ELSE STATEMENT
Click to edit Master title style

If (age >= 18){


System.out.println(“You have access!”);
}
else if(age >= 13){
System.out.println(“You need Parent Consent!”);
}
else{
System.out.println(“Access Denied!”);}
}
20 20
IF ELSE STATEMENT
Click to edit Master title style

BMI Categories:
< 18 Underweight
< 24 Normal weight
< 30 Overweight
> 30 Obesity

21 21
Click to edit Master title style

22 22
Click to edit Master title style

23 23
NESTED CONDITIONAL STATEMENT
Click to edit Master title style

A Conditional Statement within a


Conditional Statement.
The Nested Conditional Statement can be
any Type of Conditional Statement

24 24
NESTED CONDITIONAL STATEMENT
Click to edit Master title style

If (condition){
If (condition){
//Do something here
}

25 25
NESTED CONDITIONAL STATEMENT
Click to edit Master title style

If (age>=18){
If (isVerified){
System.out.println(Qualified);
}

26 26
Click to edit Master title style

27 27
Click to edit Master title style

28 28
EQUALS FUNCTION
Click to edit Master title style

To compare Strings more efficiently we


need to make use of the Equals Function
because the Equal relational operators
compares the memory address not the Content.

29 29
EQUALS FUNCTION
Click to edit Master title style

String x = “Hello”;

if(x.equals(“Hello”)){
System.out.println(“Hi there!”);
}

3030
Click to edit Master title style

31 31
Click to edit Master title style

32 32
Click to edit Master title style

33 33
Click to edit Master title style

34 34
LOGICAL OPERATORS
Click to edit Master title style

LABEL SYMBOL SYNTAX DESCRIPTION


Both conditions
AND && condition && condition
need to be true
Either conditions
OR || condition || condition
needs to be true
Inverts the current
NOT ! !condition
condition

35 35
Click to edit Master title style

36 36
Click to edit Master title style

37 37
Click to edit Master title style

3838
Click to edit Master title style

39 39
Click to edit Master title style

LESSON
ACTIVITY

40
GRADE AVERAGE PROGRAM
Click to edit Master title style

Create a program that will let the user input 4 Grades


then make the program compute the average and display a
message based on its value.
If average:
Above 100 – invalid grade
98 to 100 – With highest honors
95 to 97.99 – With high honors
90 to 94.99 – With honors
75 to 89.99 – Passed
Below 75 – Failed
41 41
GRADE AVERAGE PROGRAM
Click to edit Master title style
Sample output:
English : 95
Math : 96
Science : 94
Computer : 99

Average : 96
With High Honors

Note: The first four Outputs was from the user


42 42
Click to edit Master title style

43 43
Click to edit Master title style

44 44
Click to edit Master title style

Conditional
Statements

45
Click to edit Master title style

Thank You. ❤

46
Sir Mark Leslie D. Melendez

You might also like