0% found this document useful (0 votes)
2 views3 pages

Tutorial 5

The document outlines three activities for a programming tutorial: tracing the execution sequence of a Java program involving an Instructor and Classroom, implementing and debugging a simple banking system, and debugging a pre-written student management system. Each activity includes specific tasks such as logging transactions, verifying balances, and fixing intentional errors. Students are required to submit their source codes and documentation in a zip file to the course website.

Uploaded by

minhflash69
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Tutorial 5

The document outlines three activities for a programming tutorial: tracing the execution sequence of a Java program involving an Instructor and Classroom, implementing and debugging a simple banking system, and debugging a pre-written student management system. Each activity includes specific tasks such as logging transactions, verifying balances, and fixing intentional errors. Students are required to submit their source codes and documentation in a zip file to the course website.

Uploaded by

minhflash69
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming 2

Tutorial 5
Activity 1 - Trace the execution sequence
Determine the precise execution order of method calls and prints for the program
below:
public class Instructor { // [Link]
void prepareLesson() {
[Link]("Instructor: Preparing lesson plan...");
}

void startLecture() {
[Link]("Instructor: Starting the lecture.");
}
}

public class Classroom { // [Link]


void beginClass(Instructor inst) {
[Link]("Classroom: Opening the classroom.");
[Link]();
[Link]();
[Link]("Classroom: Class in progress...");
}
}

public class Main { // [Link]


public static void main(String[] args) {
Instructor instructor = new Instructor();
Classroom room = new Classroom();

[Link]("Main: Student arrives.");


attend(room, instructor);
[Link]("Main: Student leaves.");
}

static void attend(Classroom c, Instructor i) {


[Link]("Student: Entering classroom.");
[Link](i);
[Link]("Student: Taking notes.");
}
}
Your tasks:
1. List the execution sequence step-by-step from the moment main() starts until
the program terminates.
2. Indicate who calls whom at each step. For instance:
“main() calls attend()”
“[Link]() calls [Link]()”
3. Include the order of printed output as it appears on the console.
Tip: Follow the execution sequence example from the lecture slides. Be explicit
about when control returns to the caller.

Activity 2 - Banking System Implementation & Debugging


Goal: Practice both object interaction and systematic debugging
Scenario: Implement and debug a simple banking system
Implementation Requirements:
 Create Account class with deposit/withdraw methods
 Create Transaction class to record operations
 Implement transfer between accounts
Debugging tasks:
1. Add logging to trace all transactions
2. Verify account balances after operations
3. Handle edge cases (insufficient funds, negative amounts)

Activity 3 - Student Management


Scenario: Debug a pre-written student management system with intentional errors.
The given code is in the file [Link] which is provided with
this tutorial.
Tasks:
1. Use stack traces to locate errors
2. Apply print logging to understand flow
3. Fix each bug systematically
Document your debugging process in a MS Word file.
Submission
Submit a zip file containing all of your source codes and documents to this tutorial’s
submission box in the course website on FIT LMS.

You might also like