Back to teaching portfolio

Course Detail

CSBP221 - Programming Lab II

Object-oriented lab experience that reinforces CSBP219 concepts through guided studio assignments and projects.

Credits
1 credit hour
Contact Hours
2:30 lab per week
Prerequisite
CSBP121

Instructor Information

AbdalRaheem Al Smadi

Office: E1-3040
Phone: 03-713-5502
Email: afalsmadi@uaeu.ac.ae
Office Hours: Announced on Blackboard

Catalogue Description

Lab assignments and projects that provide hands-on practice with objects, classes, inheritance, polymorphism, and graphical user interface programming.

Textbook & Learning Resources

Teaching & Learning Methods

Course Learning Outcomes

  1. Implement algorithms using programming constructs and classes.
  2. Apply class compositions to create modular software components.
  3. Build programs with graphical user interface components.
  4. Manipulate collections of objects.
  5. Construct class hierarchies to model real-world relationships.

Topical Outline

Week Topic(s) CLOs Activities / Assessment
1Lab0: Introduction & NetBeans setup--Lab0 exercises
2Lab1: Coding simple Java algorithms, tracing output1Lab experiment / Lab1 exercises
3Lab2: File I/O, selection, exceptions1Lab experiment / Lab2 exercises
4Lab3: Repetition & methods1Lab experiment / Lab3 exercises
5Lab4: Classes, objects, constructors, accessors, mutators1Lab experiment / Lab4 exercises
6Lab5: Copy semantics, UML, this/static keywords1Lab experiment / Lab5 exercises
7Lab6: Graphical user interfaces3Lab experiment / Lab6 exercises
8Lab7: Object composition2Lab experiment / Lab7 exercises
9Lab8: Object interactions2Lab experiment / Lab8 exercises
10Midterm Exam--Assessment
11Lab9: Arrays, passing arrays to methods4Lab experiment / Lab9 exercises
12Lab10: Arrays of objects4Lab experiment / Lab10 exercises
13Lab11: Inheritance5Lab experiment / Lab11 exercises
14Lab12: Inheritance + polymorphism5Lab experiment / Lab12 exercises
15Final project presentations--Final Project

Lab Modules Overview

LabFocusWeek
Lab0Orientation & installation1
Lab1Simple algorithms & tracing2
Lab2File I/O + selection3
Lab3Loops & methods4
Lab4Classes & objects5
Lab5Copy semantics & UML6
Lab6GUI practice7
Lab7Object composition8
Lab8Object interactions9
Lab9Arrays & methods11
Lab10Arrays of objects12
Lab11Inheritance13
Lab12Polymorphism14

Lab0 - Orientation & Installation

Gather diagnostic information and ensure that Java and NetBeans run locally.

Problem: Environment Report

public class EnvironmentReport {
    public static void main(String[] args) {
        System.out.println("NetBeans installed: YES");
        System.out.println("JDK version: " + System.getProperty("java.version"));
    }
}

Problem: Welcome Message

public class WelcomeLab {
    public static void main(String[] args) {
        System.out.println("Welcome to CSBP221 Labs");
        System.out.println("Instructor: AbdalRaheem Al Smadi");
    }
}

Lab1 - Simple Algorithms

Practice translating straightforward algorithms into Java and tracing their output.

Problem: Room Capacity

import java.util.Scanner;

public class RoomCapacity {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Room capacity: ");
        int capacity = input.nextInt();
        System.out.print("Students enrolled: ");
        int enrolled = input.nextInt();
        int seatsLeft = capacity - enrolled;
        System.out.println("Seats left: " + seatsLeft);
        input.close();
    }
}

Problem: Average of Three

import java.util.Scanner;

public class AverageScores {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double total = 0;
        for (int i = 1; i <= 3; i++) {
            System.out.print("Score " + i + ": ");
            total += scanner.nextDouble();
        }
        System.out.println("Average: " + total / 3.0);
        scanner.close();
    }
}

Lab2 - File I/O & Selection

Use Java file APIs and selection statements to process external data.

Problem: Read Roster

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class RosterReader {
    public static void main(String[] args) throws IOException {
        for (String line : Files.readAllLines(Path.of("roster.txt"))) {
            if (!line.isBlank()) {
                System.out.println(line.trim());
            }
        }
    }
}

Problem: Pass/Fail Report

import java.util.Scanner;

public class PassFail {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Score: ");
        int score = scanner.nextInt();
        if (score >= 60) {
            System.out.println("Status: Pass");
        } else {
            System.out.println("Status: Fail");
        }
        scanner.close();
    }
}

Lab3 - Repetition & Methods

Apply loops and create helper methods to break down complex logic.

Problem: Factorial Method

public class Factorial {
    public static void main(String[] args) {
        System.out.println(fact(5));
    }

    static long fact(int n) {
        long result = 1;
        for (int i = 2; i <= n; i++) {
            result *= i;
        }
        return result;
    }
}

Problem: Multiplication Table

public class MultiplicationTable {
    public static void main(String[] args) {
        for (int row = 1; row <= 5; row++) {
            for (int col = 1; col <= 5; col++) {
                System.out.print((row * col) + "\t");
            }
            System.out.println();
        }
    }
}

Lab4 - Classes & Objects

Create Java classes with constructors, accessors, and mutators.

Problem: Student Class

public class Student {
    private String name;
    private double gpa;

    public Student(String name, double gpa) {
        this.name = name;
        this.gpa = gpa;
    }

    public String getName() {
        return name;
    }

    public double getGpa() {
        return gpa;
    }

    public void setGpa(double gpa) {
        this.gpa = gpa;
    }
}

Problem: Course Enrollment

public class Course {
    private String code;
    private int seats;

    public Course(String code, int seats) {
        this.code = code;
        this.seats = seats;
    }

    public boolean enroll() {
        if (seats > 0) {
            seats--;
            return true;
        }
        return false;
    }
}

Lab5 - Copy Semantics & UML

Explore copy constructors, deep vs. shallow copy, and UML-inspired structure.

Problem: Address Copy

public class Address {
    private String city;

    public Address(String city) {
        this.city = city;
    }

    public Address(Address other) {
        this.city = other.city;
    }
}

Problem: Student Copier

public class StudentInfo {
    private String name;
    private Address address;

    public StudentInfo(String name, Address address) {
        this.name = name;
        this.address = new Address(address);
    }
}

Lab6 - Graphical User Interfaces

Build basic Swing interfaces with interactive components.

Problem: Button Click

import javax.swing.*;
import java.awt.event.*;

public class HelloFrame {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Lab GUI");
        JButton button = new JButton("Say Hi");
        JLabel label = new JLabel("Ready");
        button.addActionListener(e -> label.setText("Hello, CSBP221!"));
        frame.add(button, "North");
        frame.add(label, "South");
        frame.setSize(300, 120);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Problem: Text Echo

import javax.swing.*;

public class EchoWindow {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Echo");
        JTextField input = new JTextField();
        JTextArea output = new JTextArea();
        input.addActionListener(e -> output.setText(input.getText()));
        frame.add(input, "North");
        frame.add(new JScrollPane(output), "Center");
        frame.setSize(300, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Lab7 - Object Composition

Compose objects to model richer domain entities.

Problem: Instructor & Course

public class Instructor {
    private String name;

    public Instructor(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

public class Course {
    private String code;
    private Instructor instructor;

    public Course(String code, Instructor instructor) {
        this.code = code;
        this.instructor = instructor;
    }
}

Problem: Schedule Entry

public class ScheduleEntry {
    private Course course;
    private String day;

    public ScheduleEntry(Course course, String day) {
        this.course = course;
        this.day = day;
    }
}

Lab8 - Object Interactions

Coordinate multiple objects and their behaviors.

Problem: Cart Controller

public class Cart {
    private String id;

    public Cart(String id) {
        this.id = id;
    }

    public void moveTo(String waypoint) {
        System.out.println(id + " -> " + waypoint);
    }
}

public class CartController {
    private Cart cart = new Cart("A1");
    public void dispatch() {
        cart.moveTo("Lab");
    }
}

Problem: Messaging Service

public class Messenger {
    public void send(String message) {
        System.out.println("Notifying: " + message);
    }
}

public class LabSupervisor {
    private Messenger messenger = new Messenger();
    public void alert(String msg) {
        messenger.send(msg);
    }
}

Lab9 - Arrays & Methods

Process one-dimensional arrays and pass them to helper methods.

Problem: Sum of Array

public class ArraySum {
    public static void main(String[] args) {
        int[] data = {4, 7, 11};
        System.out.println(sum(data));
    }

    static int sum(int[] values) {
        int total = 0;
        for (int value : values) {
            total += value;
        }
        return total;
    }
}

Problem: Scale Array

public class ScaleArray {
    static void scale(int[] data, int factor) {
        for (int i = 0; i < data.length; i++) {
            data[i] *= factor;
        }
    }
}

Lab10 - Arrays of Objects

Manage arrays storing custom object instances.

Problem: Student Array

public class StudentRecord {
    private String name;
    public StudentRecord(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
}

public class StudentArray {
    public static void main(String[] args) {
        StudentRecord[] records = {
            new StudentRecord("Aisha"),
            new StudentRecord("Hamad")
        };
        for (StudentRecord record : records) {
            System.out.println(record.getName());
        }
    }
}

Problem: Search Array

public class SearchStudents {
    public static int indexOf(StudentRecord[] records, String name) {
        for (int i = 0; i < records.length; i++) {
            if (records[i].getName().equalsIgnoreCase(name)) {
                return i;
            }
        }
        return -1;
    }
}

Lab11 - Inheritance

Construct class hierarchies and override base behaviors.

Problem: Course Hierarchy

public class Course {
    protected String code;
    public Course(String code) {
        this.code = code;
    }
}

public class LabCourse extends Course {
    public LabCourse(String code) {
        super(code);
    }
}

Problem: Override toString

public class LabCourse extends Course {
    private String room;
    public LabCourse(String code, String room) {
        super(code);
        this.room = room;
    }
    @Override
    public String toString() {
        return code + " in room " + room;
    }
}

Lab12 - Polymorphism

Leverage polymorphism and dynamic binding.

Problem: Payment Strategy

interface Payment {
    void pay(double amount);
}

class CardPayment implements Payment {
    public void pay(double amount) {
        System.out.println("Charging card: " + amount);
    }
}

class CashPayment implements Payment {
    public void pay(double amount) {
        System.out.println("Collecting cash: " + amount);
    }
}

Problem: Polymorphic Loop

public class PaymentRunner {
    public static void main(String[] args) {
        Payment[] payments = { new CardPayment(), new CashPayment() };
        for (Payment payment : payments) {
            payment.pay(100.0);
        }
    }
}