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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@ dist
# Vite logs files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
# Java class files
*.class

7 changes: 0 additions & 7 deletions task-1/com.hyfacademy/Main.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/exception/AlreadyEnrolledException.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/exception/CourseFullException.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/exception/EnrolmentException.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/exception/InvalidProgressException.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/model/Course.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/model/LiveCohortCourse.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/model/Mentor.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/model/SelfPacedCourse.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/model/Student.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/model/User.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/service/Enrollable.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/service/PlatformService.java

This file was deleted.

4 changes: 0 additions & 4 deletions task-1/com.hyfacademy/service/Reportable.java

This file was deleted.

10 changes: 10 additions & 0 deletions task-1/com/hyfacademy/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hyfacademy;

import com.hyfacademy.service.PlatformService;

public class Main {
public static void main(String[] args) {
PlatformService platform = new PlatformService();
platform.run();
}
}
17 changes: 17 additions & 0 deletions task-1/com/hyfacademy/exception/AlreadyEnrolledException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hyfacademy.exception;

public class AlreadyEnrolledException extends EnrolmentException {
private String studentName;
private String courseName;
public AlreadyEnrolledException(String studentName, String courseName){
super(studentName + " is already enrolled in " + courseName + " ");
this.studentName = studentName;
this.courseName = courseName;
}
public String getStudentName(){
return studentName;
}
public String getCourseName(){
return courseName;
}
}
22 changes: 22 additions & 0 deletions task-1/com/hyfacademy/exception/CourseFullException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hyfacademy.exception;

public class CourseFullException extends EnrolmentException {

private final String courseName;
private final int maxCapacity;

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

public String getCourseName() {
return courseName;
}

public int getMaxCapacity() {
return maxCapacity;
}
}

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

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

public class InvalidProgressException extends EnrolmentException {

private final int attemptedValue;

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

public int getAttemptedValue() {
return attemptedValue;
}
}

148 changes: 148 additions & 0 deletions task-1/com/hyfacademy/model/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.hyfacademy.model;

import com.hyfacademy.exception.AlreadyEnrolledException;
import com.hyfacademy.exception.CourseFullException;
import com.hyfacademy.exception.EnrolmentException;
import com.hyfacademy.exception.InvalidProgressException;
import com.hyfacademy.service.Enrollable;

public abstract class Course implements Enrollable {

private static int counter = 1;

private String courseName;
private String courseId;
private int maxStudents;
private int enrolledCount;

protected Student[] students;
protected int[] studentProgress;

public Course(String courseName, int maxStudents) {
this.courseName = courseName;
this.maxStudents = maxStudents;
this.courseId = String.format("CRS-%03d", counter++);

this.students = new Student[maxStudents];
this.studentProgress = new int[maxStudents];
this.enrolledCount = 0;
}


public String getCourseName() {
return courseName;
}

public String getCourseId() {
return courseId;
}

public int getMaxStudents() {
return maxStudents;
}

public int getEnrolledCount() {
return enrolledCount;
}

public Student[] getStudents() {
return students;
}

public int[] getStudentProgressArray() {
return studentProgress;
}


@Override
public boolean isFull() {
return enrolledCount >= maxStudents;
}

@Override
public void enrol(Student student) throws EnrolmentException {

if (isFull()) {
throw new CourseFullException(courseName, maxStudents);
}


for (int i = 0; i < enrolledCount; i++) {
if (students[i].getUserId().equals(student.getUserId())) {
throw new AlreadyEnrolledException(
student.getName(),
courseName
);
}
}


students[enrolledCount] = student;
studentProgress[enrolledCount] = 0;
enrolledCount++;

student.enrol(this);
}


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.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.getName() + " is not enrolled in '" + courseName + "'"
);
}
return studentProgress[index];
}

private int findStudentIndex(Student student) {
for (int i = 0; i < enrolledCount; i++) {
if (students[i].getUserId().equals(student.getUserId())) {
return i;
}
}
return -1;
}

protected String progressBar(int progress) {
long filled = Math.round(progress / 10.0);
int empty = (int)(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();
}

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
);
}
}

72 changes: 72 additions & 0 deletions task-1/com/hyfacademy/model/LiveCohortCourse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.hyfacademy.model;

import com.hyfacademy.exception.EnrolmentException;
import com.hyfacademy.service.Reportable;

public class LiveCohortCourse extends Course implements Reportable {

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;
}

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

@Override
public String getScheduleInfo() {
String mentorName = (mentor != null ? mentor.getName() : "No mentor assigned");
return startDate + " to " + endDate + " | Mentor: " + mentorName;
}

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

@Override
public String generateReport() {

System.out.println("══════════════════════════════════════════");
System.out.println(" COURSE REPORT — Live Cohort");
System.out.println("══════════════════════════════════════════");
System.out.println(" ID : " + getCourseId());
System.out.println(" Name : " + getCourseName());
System.out.println(" Schedule : " + startDate + " to " + endDate);
System.out.println(" Mentor : " + (mentor != null ? mentor.getName() : "None"));
System.out.println(" Capacity : " + capacityStatus());
System.out.println("──────────────────────────────────────────");
System.out.println(" STUDENT PROGRESS");
System.out.println("──────────────────────────────────────────");

int total = 0;

for (int i = 0; i < getEnrolledCount(); i++) {
Student s = students[i];
int progress = studentProgress[i];
total += progress;

System.out.printf(" %-8s %-20s %4d%% %s%n",
s.getUserId(),
s.getName(),
progress,
progressBar(progress)
);
}

System.out.println("──────────────────────────────────────────");

int avg = (getEnrolledCount() == 0) ? 0 : total / getEnrolledCount();
System.out.println(" Avg Progress : " + avg + "%");
System.out.println("══════════════════════════════════════════");

return "";
}
}
Loading