Programming 2
Tutorial 7
Activity 1 (required)
Implement a simple student management system based on the design below. The
system should store personal information (name, date of birth, student ID), GPA, and
a list of registered courses for each student.
Components:
1. Class: Student
Fields (private):
o name: String (student’s full name)
o dateOfBirth: LocalDate (date of birth)
o studentId: String (unique student ID)
o gpa: double (grade point average)
o grades: Map<Course, Double> (mapping of enrolled courses to grades)
Constructors:
o Student(String name, LocalDate dob, String sId): Initialize student
object with basic information.
Methods (public unless noted):
o Getters for all fields.
o registerCourse(Course course): adds a course to the student’s record
(without grade yet).
o assignGrade(Course course, double grade): assigns a grade for a
registered course.
o calculateGPA(): recalculates GPA as weighted average of all assigned
grades based on course credits.
o toString(): returns a formatted string with student details, GPA, and
enrolled courses.
2. Interface: Course
Methods:
o getName(): Return the name of the course (public).
o getCourseCode(): returns unique course code.
o getCredits(): returns number of credits.
3. Concrete Class: JavaCourse (implementing Course)
Fields (private):
o name: String (course name)
o courseCode: String (unique course identifier)
o credits: int (number of credits)
Constructor:
o JavaCourse(String name, String courseCode, int credits): initializes
course object.
Methods: Implement all interface methods (getName(), getCourseCode(),
getCredits()).
4. Anonymous Class:
Use an anonymous class to create a one-off course inline that implements Course.
E.g. enroll a “Special Subject” course for a student without defining a separate class.
Activity 2 (required)
Design and implement a library management system using OOP concepts in Java.
Components:
1. Interface: Item
Methods (public):
o getId(): int (returns the item ID)
o getTitle(): String (returns the item title)
o getAuthor(): String (returns the item author)
o getType(): ItemType (returns the item type, use an enum instead of
String)
2. Enum: ItemType
Defines item categories to avoid string duplication.
Values: BOOK, JOURNAL, DVD
3. Abstract Class: AbstractItem implementing Item
Fields (private):
o id: int
o title: String
o author: String
o type: ItemType
Methods:
o Standard getters (getId, getTitle, getAuthor, getType)
o toString(): String (returns formatted item information)
Subclasses:
o Book – addsfields like number of pages, publisher, publication year.
o Journal – adds fields like issue number, publication date.
o DVD – adds fields like duration, director, actors.
4. Class: Person
Fields:
o id: int
o name: String
o email: String
Methods (public):
o Getters for all fields.
o toString(): returns person information.
5. Class: Member (subclass of Person)
Fields (private):
o borrowedItems: List<Item>
Methods:
o getBorrowedItems(): List<Item> (returns an unmodifiable list)
o borrowItem(Item item): void (borrows an item, does nothing and
prints a warning message if already borrowed)
o returnItem(Item item): void (returns an item, does nothing and
prints a warning message if not borrowed)
o toString(): String (overrides to include borrowed items)
6. Class: Library
Fields (private):
o items: List<Item> (list of all items)
o members: List<Member> (list of all members)
Methods (public unless noted otherwise):
o addItem(Item item): Add an item to the library.
o removeItem(Item item): Remove an item from the library.
o findItemById(int id): Find an item by ID.
o findItemByTitle(String title): Find an item by title.
o addMember(Member member): Add a member to list of members
o removeMember(int memberId): Remove a member from the list of
members
o findMemberById(int id): Find and return a member by ID
o borrowItem(int memberId, int itemId): Allow a member to borrow
an item.
o returnItem(int memberId, int itemId): Allow a member to return
an item.
o printAllItems(): Print information of all items.
o printAllMembers(): Print information of all members.
7. Main Class:
Demonstrates usage:
Initialize library.
Add items and members.
Perform borrow/return operations.
Print all items and members.
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.