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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,12 @@ dist
vite.config.js.timestamp-*
vite.config.ts.timestamp-*



# Java compiled files
*.class

# Package Files #
*.jar
*.war
*.ear
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 service = new PlatformService();
service.run();
}
}
20 changes: 20 additions & 0 deletions task-1/com/hyfacademy/exception/AlreadyEnrolledException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hyfacademy.exception;

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

public AlreadyEnrolledException(String studentName, String courseName){
super(studentName + " is already enrolled in '" + courseName + "'");
this.studentName = studentName;
this.courseName = courseName;
}

public String getCourseName() {
return courseName;
}

public String getStudentName() {
return studentName;
}
}
20 changes: 20 additions & 0 deletions task-1/com/hyfacademy/exception/CourseFullException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 int getMaxCapacity() {
return maxCapacity;
}

public String getCourseName() {
return courseName;
}
}
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);
}
}
14 changes: 14 additions & 0 deletions task-1/com/hyfacademy/exception/InvalidProgressException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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;
}
}
153 changes: 153 additions & 0 deletions task-1/com/hyfacademy/model/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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 String courseName;
private String courseId;
private int maxStudents;
private int enrolledCount;

private Student[] enrolledStudents;
private int[] studentProgress;
private static int totalCourses;

Course(String courseName, int maxStudents){
this.courseName = courseName;
this.maxStudents = maxStudents;

this.enrolledStudents = new Student[maxStudents];
this.studentProgress = new int[maxStudents];

this.courseId = generateId();
totalCourses++;
}

private static String generateId(){
int id = totalCourses + 1;
if (id >= 100) {
return "CRS-" + id;
} else if (id >= 10) {
return "CRS-0" + id;
} else {
return "CRS-00" + id;
}
}

public String getCourseName() {
return courseName;
}

public String getCourseId() {
return courseId;
}

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

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

public int getStudentProgress(Student student) {
// returns progress (0–100); throws EnrolmentException if not enrolled
for (int i = 0; i < enrolledCount; i++) {
if (enrolledStudents[i].getName().equals(student.getName())) {
return studentProgress[i];
}
}
throw new EnrolmentException("Student not enrolled in this course.");
}

public void updateProgress(Student student, int progress) {
// throws EnrolmentException if student not enrolled.
if (progress < 0 || progress > 100) {
throw new InvalidProgressException(progress);
}
for (int i = 0; i < enrolledCount; i++) {
if (enrolledStudents[i].getName().equals(student.getName())) {
studentProgress[i] = progress;
return;
}
}
throw new EnrolmentException("Student not enrolled in this course.");
}

public static int getTotalCourses() {
return totalCourses;
}

@Override
public void enrol(Student student) {
// throws CourseFullException if at capacity, AlreadyEnrolledException if already enrolled; increments enrolledCount
if (enrolledCount >= maxStudents) {
throw new CourseFullException(getCourseName(),maxStudents);
}

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

enrolledStudents[enrolledCount] = student;
studentProgress[enrolledCount] = 0;
enrolledCount++;
}

public abstract String getCourseType();
public abstract String getScheduleInfo();

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


@Override
public String toString() {
// [CRS-001] Java Basics (Self-Paced) | Enrolled: 3/20
return String.format("[%s] %s (%s) | Enrolled: %d/%d",
courseId, courseName, getCourseType(), enrolledCount, maxStudents );
}


public void printStudentsTable() {
System.out.println("──────────────────────────────────────────");
System.out.println(" STUDENT PROGRESS");
System.out.println("──────────────────────────────────────────");

for (int i = 0; i < enrolledCount; i++) {
Student student = enrolledStudents[i];
int progress = studentProgress[i];

long filled = Math.round(progress / 10.0);

String bar = "";
for (int j = 1; j <= 10; j++) {
bar += (j <= filled) ? "█" : "░";
}

System.out.printf(" %-10s %-20s %3d%% %s\n",
student.getUserId(), student.getName(), progress, bar);
}

int total = 0;
for(int i=0; i<enrolledCount; i++) total += studentProgress[i];
int avg = (enrolledCount > 0) ? total / enrolledCount : 0;

System.out.println("──────────────────────────────────────────");
System.out.println(" Avg Progress : " + avg + "%");
System.out.println("══════════════════════════════════════════");
}


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

import com.hyfacademy.service.Reportable;

public class LiveCohortCourse extends Course implements Reportable {
public String startDate;
public String endDate;
public 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() : "Unassigned";
return startDate + " to " + endDate + " | Mentor: " + mentorName;
}

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

@Override
public void 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.getName());

System.out.println(" Capacity : " + capacityStatus());

printStudentsTable();

}
}
Loading