You will extend the HYF Academy system from Week 1 into a richer course platform. Where Week 1 focused on the basics of Java structure, this assignment puts inheritance, interfaces, polymorphism, and exception handling to work in a realistic domain.
This assignment is designed to take 1–2 days. Read the full brief before writing any code.
| Topic | Module |
|---|---|
Inheritance — superclass, subclass, super |
Module 1 |
Method overriding and @Override |
Module 1 |
| Interfaces as contracts | Module 2 |
| Multiple interface implementation | Module 2 |
| Polymorphism — mixed-type collections | Module 3 |
| Programming to an interface/supertype | Module 3 |
| Custom exception hierarchy | Module 4 |
try-catch, finally, try-with-resources |
Module 4 |
| Meaningful exception messages | Module 4 |
HYF Academy now offers two types of courses: self-paced courses that students complete in their own time, and live cohort courses that run on a fixed schedule with a mentor. Both share common properties but behave differently in key ways.
The platform also supports two types of people: Students and Mentors. Both are platform users, but they have different roles and capabilities.
com.hyfacademy
├── exception
│ ├── EnrolmentException.java
│ ├── CourseFullException.java
│ ├── AlreadyEnrolledException.java
│ └── InvalidProgressException.java
├── model
│ ├── User.java
│ ├── Student.java
│ ├── Mentor.java
│ ├── Course.java
│ ├── SelfPacedCourse.java
│ └── LiveCohortCourse.java
├── service
│ ├── Enrollable.java
│ ├── Reportable.java
│ └── PlatformService.java
└── Main.java
com.hyfacademy.exceptionCreate a custom exception hierarchy. All exceptions are unchecked (extend RuntimeException):
EnrolmentException (base — extends RuntimeException)
├── CourseFullException — carries: courseName, maxCapacity
├── AlreadyEnrolledException — carries: studentName, courseName
└── InvalidProgressException — carries: attemptedValue (int)
Each exception must:
super()Example messages:
"Course 'Java Basics' is full (max: 20 students)""Alice is already enrolled in 'Java Basics'""Progress must be between 0 and 100, but received: 150"User — com.hyfacademy.modelAbstract base class for all platform users.
Private fields: name (String), email (String), userId (String)
Constructor: all three fields
Getters for all fields
Abstract method: String getRole() — each subclass returns its own role label
Concrete method: String getSummary() — returns "[STUDENT] Alice | [email protected]"
using getRole() so subclasses automatically get the right label
Override toString() to call getSummary()
Student extends UserAdditional private fields: enrolledCourses (Course[], max 5), courseCount (int)
Constructor: name, email — auto-generate userId as "STU-001", "STU-002", etc. using a static counter
Override getRole() → returns "STUDENT"
Methods:
enrol(Course course) — adds to enrolledCourses; throws AlreadyEnrolledException if already enrolled, EnrolmentException if the student's own course list is full (5 courses max)getCourses() — returns the enrolled courses arraygetCourseCount() — returns countgetProgress(String courseName) — returns the student's progress in that course (0–100); throws EnrolmentException if not enrolledMentor extends UserAdditional private fields: expertise (String), assignedCourses (Course[], max 3), courseCount (int)
Constructor: name, email, expertise — auto-generate userId as "COA-001", "COA-002", etc.
Override getRole() → returns "MENTOR"
Methods:
assignToCourse(Course course) — adds to assigned courses; throws EnrolmentException if already at max (3 courses)getAssignedCourses() — returns assigned coursesgetExpertise() — returns expertise fieldCourse — com.hyfacademy.modelAbstract base class for all courses.
Private fields: courseName (String), courseId (String), maxStudents (int), enrolledCount (int), studentProgress (int[], parallel to a fixed-size student-name tracking array — keep it simple: track progress by index)
Static counter for auto-generating courseId as "CRS-001", "CRS-002", etc.
Constructor: courseName, maxStudents
Getters for all fields
Methods:
enrol(Student student) — throws CourseFullException if at capacity, AlreadyEnrolledException if already enrolled; increments enrolledCountupdateProgress(Student student, int progress) — throws EnrolmentException if student not enrolled, InvalidProgressException if progress outside 0–100getStudentProgress(Student student) — returns progress (0–100); throws EnrolmentException if not enrolledisFull() — returns booleanAbstract methods:
String getCourseType() — returns the type labelString getScheduleInfo() — returns schedule details (different per subclass)Override toString() →
[CRS-001] Java Basics (Self-Paced) | Enrolled: 3/20
SelfPacedCourse extends CourseStudents complete this course at their own pace — no fixed schedule.
Additional field: estimatedHours (int)