AbdalRaheem Al Smadi
Office: E1-3040
Phone: 03-713-5502
Email: afalsmadi@uaeu.ac.ae
Office Hours: Announced on Blackboard
Course Detail
Object-oriented lab experience that reinforces CSBP219 concepts through guided studio assignments and projects.
Office: E1-3040
Phone: 03-713-5502
Email: afalsmadi@uaeu.ac.ae
Office Hours: Announced on Blackboard
Lab assignments and projects that provide hands-on practice with objects, classes, inheritance, polymorphism, and graphical user interface programming.
| Week | Topic(s) | CLOs | Activities / Assessment |
|---|---|---|---|
| 1 | Lab0: Introduction & NetBeans setup | -- | Lab0 exercises |
| 2 | Lab1: Coding simple Java algorithms, tracing output | 1 | Lab experiment / Lab1 exercises |
| 3 | Lab2: File I/O, selection, exceptions | 1 | Lab experiment / Lab2 exercises |
| 4 | Lab3: Repetition & methods | 1 | Lab experiment / Lab3 exercises |
| 5 | Lab4: Classes, objects, constructors, accessors, mutators | 1 | Lab experiment / Lab4 exercises |
| 6 | Lab5: Copy semantics, UML, this/static keywords | 1 | Lab experiment / Lab5 exercises |
| 7 | Lab6: Graphical user interfaces | 3 | Lab experiment / Lab6 exercises |
| 8 | Lab7: Object composition | 2 | Lab experiment / Lab7 exercises |
| 9 | Lab8: Object interactions | 2 | Lab experiment / Lab8 exercises |
| 10 | Midterm Exam | -- | Assessment |
| 11 | Lab9: Arrays, passing arrays to methods | 4 | Lab experiment / Lab9 exercises |
| 12 | Lab10: Arrays of objects | 4 | Lab experiment / Lab10 exercises |
| 13 | Lab11: Inheritance | 5 | Lab experiment / Lab11 exercises |
| 14 | Lab12: Inheritance + polymorphism | 5 | Lab experiment / Lab12 exercises |
| 15 | Final project presentations | -- | Final Project |
| Lab | Focus | Week |
|---|---|---|
| Lab0 | Orientation & installation | 1 |
| Lab1 | Simple algorithms & tracing | 2 |
| Lab2 | File I/O + selection | 3 |
| Lab3 | Loops & methods | 4 |
| Lab4 | Classes & objects | 5 |
| Lab5 | Copy semantics & UML | 6 |
| Lab6 | GUI practice | 7 |
| Lab7 | Object composition | 8 |
| Lab8 | Object interactions | 9 |
| Lab9 | Arrays & methods | 11 |
| Lab10 | Arrays of objects | 12 |
| Lab11 | Inheritance | 13 |
| Lab12 | Polymorphism | 14 |
Gather diagnostic information and ensure that Java and NetBeans run locally.
public class EnvironmentReport {
public static void main(String[] args) {
System.out.println("NetBeans installed: YES");
System.out.println("JDK version: " + System.getProperty("java.version"));
}
}
public class WelcomeLab {
public static void main(String[] args) {
System.out.println("Welcome to CSBP221 Labs");
System.out.println("Instructor: AbdalRaheem Al Smadi");
}
}
Practice translating straightforward algorithms into Java and tracing their output.
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();
}
}
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();
}
}
Use Java file APIs and selection statements to process external data.
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());
}
}
}
}
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();
}
}
Apply loops and create helper methods to break down complex logic.
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;
}
}
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();
}
}
}
Create Java classes with constructors, accessors, and mutators.
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;
}
}
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;
}
}
Explore copy constructors, deep vs. shallow copy, and UML-inspired structure.
public class Address {
private String city;
public Address(String city) {
this.city = city;
}
public Address(Address other) {
this.city = other.city;
}
}
public class StudentInfo {
private String name;
private Address address;
public StudentInfo(String name, Address address) {
this.name = name;
this.address = new Address(address);
}
}
Build basic Swing interfaces with interactive components.
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);
}
}
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);
}
}
Compose objects to model richer domain entities.
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;
}
}
public class ScheduleEntry {
private Course course;
private String day;
public ScheduleEntry(Course course, String day) {
this.course = course;
this.day = day;
}
}
Coordinate multiple objects and their behaviors.
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");
}
}
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);
}
}
Process one-dimensional arrays and pass them to helper methods.
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;
}
}
public class ScaleArray {
static void scale(int[] data, int factor) {
for (int i = 0; i < data.length; i++) {
data[i] *= factor;
}
}
}
Manage arrays storing custom object instances.
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());
}
}
}
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;
}
}
Construct class hierarchies and override base behaviors.
public class Course {
protected String code;
public Course(String code) {
this.code = code;
}
}
public class LabCourse extends Course {
public LabCourse(String code) {
super(code);
}
}
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;
}
}
Leverage polymorphism and dynamic binding.
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);
}
}
public class PaymentRunner {
public static void main(String[] args) {
Payment[] payments = { new CardPayment(), new CashPayment() };
for (Payment payment : payments) {
payment.pay(100.0);
}
}
}