Java Lab 3 – Conditional Statements
Objective: Practice if, if-else, nested if, and switch.
Quick Recap (Cheat Sheet) Interactive Activities (Tasks)
if (condition) {
// code
1. Movie Ticket Checker
} else if (anotherCondition) { Read integer age. Print exactly: "Free Entry" if age <
// code 5; "Half Ticket" if age is between 5 and 12
} else { (inclusive); otherwise print "Full Ticket".
// code
}
switch(value) {
2. Electricity Bill
case 'S': // code; break;
Input units consumed (integer). Use conditional logic
case 'M': // code; break;
to print one of: "Low usage" (<100), "Medium
default: // code;
usage" (100–300 inclusive), or "High usage" (>300).
}
Predict & Run (Puzzle)
int x = 7; 3. Tea Shop Menu
if (x % 2 == 0) Read a character size (S, M, L). Print the price: S ->
System.out.println("Even"); 50; M -> 80; L -> 120. Use switch on the
else if (x % 3 == 0) character.
System.out.println("Divisible by 3");
else
char size = 'M';
System.out.println("Other"); // What will this print?
switch (size) {
case 'S': System.out.println(50); break;
case 'M': System.out.println(80); break;
case 'L': System.out.println(120); break;
Notes / Output default: System.out.println("Invalid size");
MK Tech – Java Lab Handout • Single-page, print-ready (A4)