Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions task-1/com.hyfacademy/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.hyfacademy;

import com.hyfacademy.service.*;

public class Main {
static void main(String[] args) {
System.out.println("Hello World!");
public static void main(String[] args) {
PlatformService service = new PlatformService();
service.run();
}
}
12 changes: 11 additions & 1 deletion task-1/com.hyfacademy/exception/AlreadyEnrolledException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package com.hyfacademy.exception;

public class AlreadyEnrolledException {
public class AlreadyEnrolledException extends EnrolmentException {
private final String studentName;
private final String courseName;

public AlreadyEnrolledException(String studentName, String courseName){
super(String.format("%s is already enrolled in '%s'", studentName, courseName));
this.studentName = studentName;
this.courseName = courseName;
}
public String getStudentName() { return studentName; }
public String getCourseName() { return courseName; }
}
15 changes: 14 additions & 1 deletion task-1/com.hyfacademy/exception/CourseFullException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
package com.hyfacademy.exception;

public class CourseFullException {
public class CourseFullException extends EnrolmentException {
private final String courseName;
private final int maxCapacity;

public CourseFullException(String courseName, int maxCapacity) {
super(String.format("Course '%s' is full (max: %d students)", courseName, maxCapacity));
this.courseName = courseName;
this.maxCapacity = maxCapacity;
}

public String getCourseName() { return courseName; }
public int getMaxCapacity() { return maxCapacity; }


}
5 changes: 4 additions & 1 deletion task-1/com.hyfacademy/exception/EnrolmentException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.hyfacademy.exception;

public class EnrolmentException {
public class EnrolmentException extends RuntimeException {
public EnrolmentException(String message){
super(message);
}
}
11 changes: 10 additions & 1 deletion task-1/com.hyfacademy/exception/InvalidProgressException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package com.hyfacademy.exception;

public class InvalidProgressException {
public class InvalidProgressException extends EnrolmentException {
private final int attemptedValue;

public InvalidProgressException(int attemptedValue){
super(String.format("Progress must be between 0 and 100, but received: %d", attemptedValue));
this.attemptedValue = attemptedValue;
}

// Getter
public int getAttemptedValue() {return attemptedValue;}
}
99 changes: 98 additions & 1 deletion task-1/com.hyfacademy/model/Course.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,101 @@
package com.hyfacademy.model;
import com.hyfacademy.exception.*;
import com.hyfacademy.service.Enrollable;
import com.hyfacademy.service.Reportable;

public abstract class Course implements Enrollable, Reportable {
private String courseName;
private String courseId;
private int maxStudents;
private int enrolledCount;

// parallel array
private int[] studentProgress;
private Student[] enrolledStudents;

public static int totalCourses = 0;
public Course (String courseName, int maxStudents){
totalCourses++;
this.courseId = "CRS-" + String.format("%03d", totalCourses);
this.courseName = courseName;
this.maxStudents = maxStudents;
this.enrolledCount = 0;
this.studentProgress = new int[maxStudents];
this.enrolledStudents = new Student[maxStudents];
}

// getters
public String getCourseName() {return courseName;}
public String getCourseId() {return courseId;}
// getters for enrolled students and progress
public Student[] getEnrolledStudents() {return enrolledStudents;}
public int[] getStudentProgress() {return studentProgress;}

@Override
public int getMaxStudents() {return maxStudents;}
@Override
public int getEnrolledCount() {return enrolledCount;}



// help to search student index array
private int findStudentIndex(Student student) {
for (int i = 0; i < enrolledCount; i++) {
if (enrolledStudents[i] != null && enrolledStudents[i].equals(student)) {
return i;
}
}
return -1;
}

// check if the course is full
@Override
public boolean isFull() {
return enrolledCount >= maxStudents;
}

// Methods
@Override
public void enrol(Student student) throws CourseFullException, AlreadyEnrolledException {
if (isFull()) {
throw new CourseFullException(this.courseName, this.maxStudents);
}
for (int i = 0; i < enrolledCount; i++) {
if (enrolledStudents[i].equals(student)) {
throw new AlreadyEnrolledException(student.getName(), this.courseName);
}
}
enrolledStudents[enrolledCount] = student;
studentProgress[enrolledCount] = 0;
enrolledCount++;
}

public void updateProgress(Student student, int progress) throws EnrolmentException, InvalidProgressException {
if (progress < 0 || progress > 100 ){
throw new InvalidProgressException(progress);
}
int index = findStudentIndex(student);
if (index == -1) {
throw new EnrolmentException("Student " + student.getName() + " is not enrolled in " + courseName);
}
studentProgress[index] = progress;
}
public int getStudentProgress(Student student) throws EnrolmentException {
int index = findStudentIndex(student);
if (index == -1) {
throw new EnrolmentException("Student " + student.getName() + " is not enrolled in " + courseName);
}
return studentProgress[index];
}

//Abstract Methods
public abstract String getCourseType();
public abstract String getScheduleInfo();

@Override
public String toString() {
return String.format("[%s] %s (%s) | Enrolled: %d/%d",
courseId, courseName, getCourseType(), enrolledCount, maxStudents);
}

public class Course {
}
88 changes: 86 additions & 2 deletions task-1/com.hyfacademy/model/LiveCohortCourse.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,88 @@
package com.hyfacademy.model;
import com.hyfacademy.exception.*;

public class LiveCohortCourse {
}

public class LiveCohortCourse extends Course {
private String startDate;
private String endDate;
private Mentor mentor;

public LiveCohortCourse(String courseName, int maxStudents, String startDate, String endDate) {
super(courseName, maxStudents);
this.startDate = startDate;
this.endDate = endDate;
}

// Getters
public String getStartDate() { return startDate; }
public String getEndDate() { return endDate; }
public Mentor getMentor() { return mentor; }

// Methods
public void assignMentor(Mentor mentor) throws EnrolmentException {
mentor.assignToCourse(this);
this.mentor = mentor;
}

@Override
public String getCourseType() {
return "Live Cohort";
}

@Override
public String getScheduleInfo() {
String mentorName = (mentor != null) ? mentor.getName() : "TBD";
return String.format("%s to %s | Mentor: %s", startDate, endDate, mentorName);
}

@Override
public void generateReport() {
Student[] students = getEnrolledStudents();
int[] progress = getStudentProgress();
int enrolledCount = getEnrolledCount();

// Calculate average progress
int totalProgress = 0;
for (int i = 0; i < enrolledCount; i++) {
totalProgress += progress[i];
}
int avgProgress = enrolledCount > 0 ? totalProgress / enrolledCount : 0;

// Determine capacity status
String capacityStatus = enrolledCount >= getMaxStudents() ? "Full" : "Open";

System.out.println("══════════════════════════════════════════");
System.out.println(" COURSE REPORT — Live Cohort");
System.out.println("══════════════════════════════════════════");
System.out.printf(" %-12s: %s\n", "ID", getCourseId());
System.out.printf(" %-12s: %s\n", "Name", getCourseName());
System.out.printf(" %-12s: %s to %s\n", "Schedule", startDate, endDate);
System.out.printf(" %-12s: %s\n", "Mentor", (mentor != null) ? mentor.getName() : "Not assigned");
System.out.printf(" %-12s: %d/%d — %s\n", "Capacity", enrolledCount, getMaxStudents(), capacityStatus);
System.out.println("──────────────────────────────────────────");
System.out.println(" STUDENT PROGRESS");
System.out.println("──────────────────────────────────────────");

for (int i = 0; i < enrolledCount; i++) {
Student student = students[i];
int studentProgress = progress[i];
String progressBar = createProgressBar(studentProgress);
System.out.printf(" %-6s%-22s%3d%% %s\n",
student.getUserId(), student.getName(), studentProgress, progressBar);
}

System.out.println("──────────────────────────────────────────");
System.out.printf(" Avg Progress : %d%%\n", avgProgress);
System.out.println("══════════════════════════════════════════");
}

private String createProgressBar(int progress) {
int filled = progress / 10;
int empty = 10 - filled;
StringBuilder bar = new StringBuilder();
for (int i = 0; i < filled; i++) bar.append("█");
for (int i = 0; i < empty; i++) bar.append("░");
return bar.toString();
}

}
42 changes: 41 additions & 1 deletion task-1/com.hyfacademy/model/Mentor.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
package com.hyfacademy.model;
import com.hyfacademy.exception.EnrolmentException;

public class Mentor extends User{
private String expertise;
private Course[] assignedCourses;
private int courseCount;
private static int totalMentors = 0;

public Mentor(String name, String email, String expertise){
totalMentors++;
super(name, email, String.format("COA-%03d", totalMentors));
this.expertise = expertise;
this.assignedCourses = new Course[3];
this.courseCount = 0;
}
@Override
public String getRole(){
return "MENTOR";
}

// Getters
public Course[] getAssignedCourses() {return assignedCourses;}
public String getExpertise() {return expertise;}
public int getCourseCount() {return courseCount;}

// Methods
public void assignToCourse(Course course) throws EnrolmentException {
// mentor's capacity check
if (courseCount >= 3) {
throw new EnrolmentException("Mentor " + getName() + " is already at maximum course capacity (3).");
}
// check if the mentor already assigned
for (int i = 0; i < courseCount; i++) {
if (assignedCourses[i].getCourseId().equals(course.getCourseId())) {
throw new EnrolmentException("Mentor is already assigned to " + course.getCourseName());
}
}
assignedCourses[courseCount] = course;
courseCount++;
}


public class Mentor {
}
67 changes: 66 additions & 1 deletion task-1/com.hyfacademy/model/SelfPacedCourse.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,69 @@
package com.hyfacademy.model;

public class SelfPacedCourse {
public class SelfPacedCourse extends Course {
private int estimatedHours;

public SelfPacedCourse(String courseName, int maxStudents, int estimatedHours) {
super(courseName, maxStudents);
this.estimatedHours = estimatedHours;
}

@Override
public String getCourseType() {
return "Self-Paced";
}

@Override
public String getScheduleInfo() {
return String.format("Estimated: %d hours — complete at your own pace", estimatedHours);
}

@Override
public void generateReport() {
Student[] students = getEnrolledStudents();
int[] progress = getStudentProgress();
int enrolledCount = getEnrolledCount();

// Calculate average progress
int totalProgress = 0;
for (int i = 0; i < enrolledCount; i++) {
totalProgress += progress[i];
}
int avgProgress = enrolledCount > 0 ? totalProgress / enrolledCount : 0;

// Determine capacity status
String capacityStatus = enrolledCount >= getMaxStudents() ? "Full" : "Open";

System.out.println("══════════════════════════════════════════");
System.out.println(" COURSE REPORT — Self-Paced");
System.out.println("══════════════════════════════════════════");
System.out.printf(" %-12s: %s\n", "ID", getCourseId());
System.out.printf(" %-12s: %s\n", "Name", getCourseName());
System.out.printf(" %-12s: %d/%d — %s\n", "Capacity", enrolledCount, getMaxStudents(), capacityStatus);
System.out.printf(" %-12s: %d\n", "Est. Hours", estimatedHours);
System.out.println("──────────────────────────────────────────");
System.out.println(" STUDENT PROGRESS");
System.out.println("──────────────────────────────────────────");

for (int i = 0; i < enrolledCount; i++) {
Student student = students[i];
int studentProgress = progress[i];
String progressBar = createProgressBar(studentProgress);
System.out.printf(" %-6s%-22s%3d%% %s\n",
student.getUserId(), student.getName(), studentProgress, progressBar);
}

System.out.println("──────────────────────────────────────────");
System.out.printf(" Avg Progress : %d%%\n", avgProgress);
System.out.println("══════════════════════════════════════════");
}

private String createProgressBar(int progress) {
int filled = progress / 10;
int empty = 10 - filled;
StringBuilder bar = new StringBuilder();
for (int i = 0; i < filled; i++) bar.append("█");
for (int i = 0; i < empty; i++) bar.append("░");
return bar.toString();
}
}
Loading