Lab Activity - Class 8 - Decision Control Structure

Lab Activity — Decision Control Structure
Learn by Doing — Code, Test and Grow! This hands-on lab activity contains 10 real Java programs to help you master decision control statements (if, if-else, nested if, else-if ladder) using BlueJ IDE. Complete all tasks and become a confident Java programmer!
Introduction
Welcome to your Decision Control Structure Lab Activity! The best way to learn programming is by writing and running actual code. In this lab, you'll code 10 different programs covering all types of decision statements.
By the end of this activity, you'll be comfortable with
if, if-else, nested if,
and else-if ladder — the building blocks of
almost every program!
- Duration: 2-3 lab periods
- Total Marks: 100
- Format: BlueJ IDE + Notebook
- Language: Java
Motivational Tip
Coding is like riding a bicycle — you can watch tutorials all day, but you'll only really learn by doing it yourself. Every program you write makes you a better programmer!
Objective
To understand and implement decision control statements (if, if-else, nested if, else-if ladder) using Java in BlueJ IDE.
Requirements
What You Need
- ✅ Computer with BlueJ IDE installed.
- ✅ JDK (Java Development Kit).
- ✅ Notepad or Text Editor.
- ✅ Working Internet (optional).
- ✅ Notebook and Pen.
Learning Outcomes
After This Lab, You Can
- ⭐ Write if statements
- ⭐ Use if-else statements
- ⭐ Implement nested if
- ⭐ Create else-if ladder
- ⭐ Test edge cases
- ⭐ Debug decision programs
10 Lab Tasks (Complete All Programs)
Task 1: Check Positive or Negative Number
Positive / Negative / Zero
Requirement: Take a number as input. If positive, print "Positive". If negative, print "Negative". If zero, print "Zero".
import java.util.Scanner;
public class CheckNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num > 0) {
System.out.println("Positive");
} else if (num < 0) {
System.out.println("Negative");
} else {
System.out.println("Zero");
}
}
}
Task 2: Even or Odd Number
Even or Odd
Requirement: Take a number input. Check if divisible by 2. Print "Even" or "Odd".
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
Task 3: Find Largest of Two Numbers
Largest of Two
Requirement: Input two numbers. Compare them. Print the larger one.
import java.util.Scanner;
public class LargestOfTwo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();
if (a > b) {
System.out.println(a + " is larger");
} else if (b > a) {
System.out.println(b + " is larger");
} else {
System.out.println("Both are equal");
}
}
}
Task 4: Find Largest of Three Numbers
Largest of Three
Requirement: Input three numbers. Find and print the largest.
import java.util.Scanner;
public class LargestOfThree {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter three numbers: ");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a >= b && a >= c) {
System.out.println(a + " is largest");
} else if (b >= c) {
System.out.println(b + " is largest");
} else {
System.out.println(c + " is largest");
}
}
}
Task 5: Voting Eligibility Check
Voting Eligibility
Requirement: Input age. If >= 18 print "Can Vote", else print "Cannot Vote".
import java.util.Scanner;
public class VotingEligibility {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = sc.nextInt();
if (age >= 18) {
System.out.println("Can Vote");
} else {
System.out.println("Cannot Vote");
}
}
}
Task 6: Grade Calculator
Grade Calculator
Requirement: Input marks (0-100). Print Grade: A (>=90), B (>=75), C (>=60), D (>=40), F (<40).
import java.util.Scanner;
public class GradeCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter marks: ");
int marks = sc.nextInt();
if (marks >= 90) {
System.out.println("Grade: A");
} else if (marks >= 75) {
System.out.println("Grade: B");
} else if (marks >= 60) {
System.out.println("Grade: C");
} else if (marks >= 40) {
System.out.println("Grade: D");
} else {
System.out.println("Grade: F");
}
}
}
Task 7: Leap Year Checker
Leap Year Checker
Requirement: Input year. Check if divisible by 4 (leap year). Print "Leap Year" or "Not Leap Year".
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter year: ");
int year = sc.nextInt();
if (year % 4 == 0) {
System.out.println("Leap Year");
} else {
System.out.println("Not Leap Year");
}
}
}
Task 8: Positive/Negative and Even/Odd
Combined Check
Requirement: Input number. Check both positive/negative AND even/odd.
import java.util.Scanner;
public class CombinedCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();
if (num > 0) {
if (num % 2 == 0) {
System.out.println("Positive and Even");
} else {
System.out.println("Positive and Odd");
}
} else if (num < 0) {
if (num % 2 == 0) {
System.out.println("Negative and Even");
} else {
System.out.println("Negative and Odd");
}
} else {
System.out.println("Zero");
}
}
}
Task 9: Simple Calculator
Simple Calculator
Requirement: Input two numbers and operator (+, -, *, /). Perform operation and display result.
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
double a = sc.nextDouble();
System.out.print("Enter operator (+, -, *, /): ");
char op = sc.next().charAt(0);
System.out.print("Enter second number: ");
double b = sc.nextDouble();
double result = 0;
if (op == '+') {
result = a + b;
} else if (op == '-') {
result = a - b;
} else if (op == '*') {
result = a * b;
} else if (op == '/') {
if (b != 0) {
result = a / b;
} else {
System.out.println("Cannot divide by zero!");
return;
}
} else {
System.out.println("Invalid operator!");
return;
}
System.out.println("Result: " + result);
}
}
Task 10: Traffic Light Signal
Traffic Light Signal
Requirement: Input color (RED, YELLOW, GREEN). Print action (Stop / Ready / Go).
import java.util.Scanner;
public class TrafficLight {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter light color (RED/YELLOW/GREEN): ");
String color = sc.next().toUpperCase();
if (color.equals("RED")) {
System.out.println("Stop");
} else if (color.equals("YELLOW")) {
System.out.println("Ready");
} else if (color.equals("GREEN")) {
System.out.println("Go");
} else {
System.out.println("Invalid color!");
}
}
}
Submission Format
For each task, include:
What to Submit
- ✅ Program title
- ✅ Java source code (.java file)
- ✅ Screenshot of output
- ✅ Test cases with results
- ✅ Observations / Notes
Evaluation Criteria (Total: 100 Marks)
| Criteria | Marks |
|---|---|
| Program compilation | 20 |
| Correct output | 30 |
| Code quality (indentation, naming) | 20 |
| Test cases handled | 15 |
| Comments & documentation | 10 |
| Punctuality | 5 |
| Total | 100 Marks |
Tips for Success
Success Tips
- 📖 Read task carefully before coding.
- 📝 Write pseudocode first.
- 🧪 Test with different inputs.
- 🏷️ Use meaningful variable names.
- 💬 Add comments to explain logic.
- 👨🏫 Ask your teacher if stuck.
- 🔄 Practice regularly.
- 🐛 Debug patiently.
- 🎯 Test edge cases.
- 📋 Keep track of your progress.
Common Errors to Avoid
Watch Out for These!
- ❌ Using = instead of ==
- ❌ Missing braces { }
- ❌ Wrong operator precedence
- ❌ Forgetting else block
- ❌ Not handling zero/negative
- ❌ Case-sensitive issues (Java is case-sensitive!)
- ❌ Not testing edge cases
- ❌ Using == for strings (use .equals())
How to Run Your Programs in BlueJ
Create New Project
Open BlueJ → Project → New Project → Give a name → OK
Create New Class
Click "New Class" → Enter class name (e.g., CheckNumber) → OK
Write Code
Double-click the class → Delete default code → Type your program.
Compile
Click "Compile" button. Fix any errors that appear.
Run Program
Right-click class → "void main(String[] args)" → OK → Enter inputs in Terminal.
Take Screenshot
Capture the terminal output showing your program working correctly.
Suggested Timeline
| Day | Tasks to Complete |
|---|---|
| Lab 1 - Day 1 | Tasks 1-3 (Positive/Negative, Even/Odd, Largest of 2) |
| Lab 1 - Day 2 | Tasks 4-5 (Largest of 3, Voting Eligibility) |
| Lab 2 - Day 1 | Tasks 6-7 (Grade Calculator, Leap Year) |
| Lab 2 - Day 2 | Tasks 8-9 (Positive Even/Odd, Calculator) |
| Lab 3 | Task 10 (Traffic Light) + Testing + Documentation |
Did You Know?
Fun Fact
Practice makes a programmer perfect! The more you code, the better you become at solving problems. Famous programmers write thousands of lines of code before they master programming. Every line you write today builds your future skills!
Bonus Challenge Tasks (Optional)
Extra Practice
- 🌟 Check if a triangle is Equilateral, Isosceles, or Scalene (from 3 sides).
- 🌟 Find the largest of 4 numbers.
- 🌟 Check if a character is vowel or consonant.
- 🌟 Print the day name based on day number (1-7).
- 🌟 Simple ATM Program (check PIN and withdraw).
- 🌟 BMI Calculator (Underweight/Normal/Overweight).
- 🌟 Season Finder based on month number.
- 🌟 Number to word conversion (1-10).
Frequently Asked Questions
Q1. What if my program doesn't compile?
Read the error message carefully. Common issues: missing semicolon, missing braces, misspelled keywords. Fix and try again!
Q2. Should I use Scanner or command-line arguments?
For beginners, use Scanner. It's easier to test interactively. Command-line arguments are for advanced programs.
Q3. What if I get wrong output?
Check your logic. Print variable values to see what's happening. Use test cases to verify.
Q4. Can I skip a task?
You need to complete all 10 tasks for full marks. Ask for help if you're stuck.
Q5. Should I add comments?
Yes! Comments help you and others understand the code. They also earn marks.
Q6. What's the best way to test?
Test with normal cases, edge cases (0, negative), maximum values, and invalid inputs.
Q7. Can I work with a friend?
You can discuss ideas, but write your own code. Copying is not learning!
Q8. What if I don't have BlueJ at home?
BlueJ is free! Download from bluej.org. It works on Windows, Mac, and Linux.
Key Takeaways
- Complete all 10 Java programs.
- Use BlueJ IDE for coding.
- Test with multiple inputs.
- Take screenshots of outputs.
- Follow best practices.
- Handle edge cases.
- Add comments to code.
- Total marks: 100.
- Try bonus challenges for extra practice.
- Have fun coding!
Key Takeaway
Lab activities help you learn programming
concepts by hands-on practice! Code, test,
debug and learn. That's the programming way!
This lab isn't just about scoring marks — it's about
becoming a real programmer. Every task teaches you
something new about decision-making in code.
Complete all 10 programs. Ask for help when
needed. You will become a Java expert!
⭐ CODE SMART, THINK CLEAR, WRITE BETTER! ⭐
Best of Luck! Practice makes perfect.
Every program you write brings you closer to being a
great programmer! 👍😊
Flowchart → Visual Thinking → Smart Solutions → Better
Results! 🚀
Home & Online Tuition
Learn from an experienced tutor with personalized guidance.
Available Locations
Expert Home & Online Tuition
Personalized one-to-one tuition that focuses on concept building, practical learning, problem-solving skills, and excellent academic performance. Suitable for school students looking for structured, interactive, and result-oriented learning.
Subjects We Teach
Why Choose Our Tuition?
✅ Concept-Based Learning
✅ Practical Examples
✅ Weekly Tests
✅ Doubt Solving Sessions
✅ Practice Worksheets
✅ MCQ & Assignments
✅ Exam Preparation
✅ Flexible Class Timings