From c68e40572df253e597540c89143d42bef8681bb9 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Tue, 12 May 2026 12:37:48 +0200 Subject: [PATCH 1/6] finish with exceptions --- .../exception/AlreadyEnrolledException.java | 13 ++++++++++++- .../exception/CourseFullException.java | 13 ++++++++++++- .../exception/EnrolmentException.java | 5 ++++- .../exception/InvalidProgressException.java | 14 ++++++++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java b/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java index a82837e..ccb7293 100644 --- a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java +++ b/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java @@ -1,4 +1,15 @@ package com.hyfacademy.exception; -public class AlreadyEnrolledException { +public class AlreadyEnrolledException extends EnrolmentException { + private String studentName; + private 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;} } diff --git a/task-1/com.hyfacademy/exception/CourseFullException.java b/task-1/com.hyfacademy/exception/CourseFullException.java index 11a76f1..f4ddaee 100644 --- a/task-1/com.hyfacademy/exception/CourseFullException.java +++ b/task-1/com.hyfacademy/exception/CourseFullException.java @@ -1,4 +1,15 @@ package com.hyfacademy.exception; -public class CourseFullException { +public class CourseFullException extends EnrolmentException{ + private String courseName; + private 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;} } diff --git a/task-1/com.hyfacademy/exception/EnrolmentException.java b/task-1/com.hyfacademy/exception/EnrolmentException.java index 8454c32..4b922dd 100644 --- a/task-1/com.hyfacademy/exception/EnrolmentException.java +++ b/task-1/com.hyfacademy/exception/EnrolmentException.java @@ -1,4 +1,7 @@ package com.hyfacademy.exception; -public class EnrolmentException { +public class EnrolmentException extends RuntimeException { + public EnrolmentException(String message){ + super(message); + } } diff --git a/task-1/com.hyfacademy/exception/InvalidProgressException.java b/task-1/com.hyfacademy/exception/InvalidProgressException.java index c0c0037..68bb3ad 100644 --- a/task-1/com.hyfacademy/exception/InvalidProgressException.java +++ b/task-1/com.hyfacademy/exception/InvalidProgressException.java @@ -1,4 +1,14 @@ package com.hyfacademy.exception; -public class InvalidProgressException { -} +public class InvalidProgressException extends EnrolmentException{ + private int attemptedValue; + + public InvalidProgressException(int attemptedValue){ + super(String.format("Progress must be between 0 and 100, but received: %d", attemptedValue)); + this.attemptedValue = attemptedValue; + } + + public int getAttemptedValue(){return attemptedValue;} + + +} \ No newline at end of file From 04820778a8cb2409291fd5662fb1b9d46b98ef44 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Tue, 12 May 2026 15:07:55 +0200 Subject: [PATCH 2/6] add User, Mentor, Student classes, start Course --- .../exception/AlreadyEnrolledException.java | 4 +- .../exception/CourseFullException.java | 4 +- .../exception/InvalidProgressException.java | 2 +- task-1/com.hyfacademy/model/Course.java | 54 +++++++++++++++++- task-1/com.hyfacademy/model/Mentor.java | 43 +++++++++++++- task-1/com.hyfacademy/model/Student.java | 56 ++++++++++++++++++- task-1/com.hyfacademy/model/User.java | 28 +++++++++- 7 files changed, 182 insertions(+), 9 deletions(-) diff --git a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java b/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java index ccb7293..10a035b 100644 --- a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java +++ b/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java @@ -1,8 +1,8 @@ package com.hyfacademy.exception; public class AlreadyEnrolledException extends EnrolmentException { - private String studentName; - private String courseName; + 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)); diff --git a/task-1/com.hyfacademy/exception/CourseFullException.java b/task-1/com.hyfacademy/exception/CourseFullException.java index f4ddaee..7334592 100644 --- a/task-1/com.hyfacademy/exception/CourseFullException.java +++ b/task-1/com.hyfacademy/exception/CourseFullException.java @@ -1,8 +1,8 @@ package com.hyfacademy.exception; public class CourseFullException extends EnrolmentException{ - private String courseName; - private int maxCapacity; + 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)); diff --git a/task-1/com.hyfacademy/exception/InvalidProgressException.java b/task-1/com.hyfacademy/exception/InvalidProgressException.java index 68bb3ad..5ded65d 100644 --- a/task-1/com.hyfacademy/exception/InvalidProgressException.java +++ b/task-1/com.hyfacademy/exception/InvalidProgressException.java @@ -1,7 +1,7 @@ package com.hyfacademy.exception; public class InvalidProgressException extends EnrolmentException{ - private int attemptedValue; + private final int attemptedValue; public InvalidProgressException(int attemptedValue){ super(String.format("Progress must be between 0 and 100, but received: %d", attemptedValue)); diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java index e80513e..e8d7a4d 100644 --- a/task-1/com.hyfacademy/model/Course.java +++ b/task-1/com.hyfacademy/model/Course.java @@ -1,4 +1,56 @@ package com.hyfacademy.model; -public class Course { +import com.hyfacademy.exception.AlreadyEnrolledException; +import com.hyfacademy.exception.CourseFullException; + +public abstract class Course { + private final String courseName; + private final String courseId; + private int maxStudents; + private int enrolledCount = 0; + private int[] studentProgress = new int[maxStudents]; + private Student[] enrolledStudent = new Student[maxStudents]; + static int courseCounter = 0; + + public Course(String courseName, int maxStudents){ + this.courseName = courseName; + this.maxStudents = maxStudents; + this.courseId = generateCourseId(); + } + + public String getCourseName(){return courseName;} + public int getMaxStudents(){return maxStudents;} + public String getCourseId(){return courseId;} + 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 void enrol(Student student){ + if(enrolledCount == maxStudents){ + throw new CourseFullException(courseName, maxStudents); + } + + for(Course c : student.getCourses()){ + if(c !=null && c.equals(this)){ + throw new AlreadyEnrolledException(student.getName(), courseName); + } + } + student.enrol(this); + enrolledStudent[enrolledCount] = student; + studentProgress[enrolledCount] = 0; + enrolledCount ++; + } + + + + public static String generateCourseId(){ + courseCounter ++; + return String.format("CRS-%03d", courseCounter); + }; + + } diff --git a/task-1/com.hyfacademy/model/Mentor.java b/task-1/com.hyfacademy/model/Mentor.java index b8738d5..72b0805 100644 --- a/task-1/com.hyfacademy/model/Mentor.java +++ b/task-1/com.hyfacademy/model/Mentor.java @@ -1,4 +1,45 @@ package com.hyfacademy.model; -public class Mentor { +import com.hyfacademy.exception.EnrolmentException; + +public class Mentor extends User { + private String expertise; + private Course[] assignedCourses = new Course[3]; + private int courseCounter = 0; + + private static int mentorCounter = 0; + + public Mentor(String name, String email, String expertise){ + super(name, email, generateMentorId()); + this.expertise = expertise; + } + + public String getExpertise(){return expertise;} + public Course[] getAssignedCourses(){return assignedCourses;} + + @Override + public String getRole(){return "MENTOR";} + + public void assignToCourse(Course course){ + if(courseCounter == 3){ + throw new EnrolmentException( + String.format("Mentor %s cannot be assigned to more than 3 courses", getName()) + ); + } + + for(Course c : assignedCourses){ + if(c!=null && c.equals(course)){ + throw new EnrolmentException( + String.format("Mentor %s has already been assigned to %s course", getName(), course.getCourseName())); + } + } + + assignedCourses[courseCounter] = course; + courseCounter++; + } + + public static String generateMentorId(){ + mentorCounter ++; + return String.format("COA-%03d", mentorCounter); + } } diff --git a/task-1/com.hyfacademy/model/Student.java b/task-1/com.hyfacademy/model/Student.java index 9f34d88..2a43219 100644 --- a/task-1/com.hyfacademy/model/Student.java +++ b/task-1/com.hyfacademy/model/Student.java @@ -1,4 +1,58 @@ package com.hyfacademy.model; -public class Student { +import com.hyfacademy.exception.AlreadyEnrolledException; +import com.hyfacademy.exception.EnrolmentException; + +public class Student extends User { + private Course[] enrolledCourses = new Course[5]; + private int courseCounter = 0; + + private static int studentCounter = 0; + + public Student(String name, String email){ + super(name, email, generateStudentId()); + } + + @Override + public String getRole(){ + return "STUDENT"; + } + + public Course[] getCourses(){return enrolledCourses;} + public int getCourseCount(){return courseCounter;} + + public void enrol(Course course){ + if(courseCounter == 5){ + throw new EnrolmentException( + String.format("%s own course list is full (5 courses max)", getName())); + } + + for(Course c : enrolledCourses){ + if(c != null && c.equals(course)){ + throw new AlreadyEnrolledException(getName(), c.getCourseName()); + } + } + + enrolledCourses[courseCounter] = course; + courseCounter ++; + } + +// BACK AFTER COURSE CLASS CREATE! +// public String getProgress(String courseName){ +// for(Course c : enrolledCourses){ +// if(c != null && c.getCourseName.equals(courseName)){continue;} +// else{throw new EnrolmentException(String.format("%s doesn't enroll in '%s' course.", getName(), courseName));} +// } +// +// return String.format("%s progress in course '%s' equal to ", getName(), courseName) +// +// } + + public static String generateStudentId(){ + studentCounter ++; + return String.format("STU-%03d", studentCounter); + } + + + } diff --git a/task-1/com.hyfacademy/model/User.java b/task-1/com.hyfacademy/model/User.java index 43cba56..b1e52c0 100644 --- a/task-1/com.hyfacademy/model/User.java +++ b/task-1/com.hyfacademy/model/User.java @@ -1,4 +1,30 @@ package com.hyfacademy.model; -public class User { +public abstract class User { + private final String name; + private final String email; + private final String userId; + + public User(String name, String email, String userId){ + this.name = name; + this.email = email; + this.userId = userId; + } + + public String getName(){return name;} + public String getEmail(){return email;} + public String getUserId(){return userId;} + + public abstract String getRole(); + + public String getSummary(){ + return String.format("[%s] %s | %s", getRole().toUpperCase(), name, email); + } + + @Override + + public String toString(){ + return getSummary(); + } + } From d614cd70e5b4f1f242e0a1b7d2058c1d9746034c Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Wed, 13 May 2026 19:07:42 +0200 Subject: [PATCH 3/6] finish with abstract Course class --- task-1/com.hyfacademy/Main.java | 25 +++++++++++- task-1/com.hyfacademy/model/Course.java | 50 +++++++++++++++++++++--- task-1/com.hyfacademy/model/Student.java | 19 +++++---- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/task-1/com.hyfacademy/Main.java b/task-1/com.hyfacademy/Main.java index d97363c..d713980 100644 --- a/task-1/com.hyfacademy/Main.java +++ b/task-1/com.hyfacademy/Main.java @@ -1,7 +1,28 @@ package com.hyfacademy; + +import com.hyfacademy.model.Mentor; +import com.hyfacademy.model.Student; + public class Main { - static void main(String[] args) { - System.out.println("Hello World!"); + public static void main(String[] args) { + + + Student s1 = new Student("Alex Lirman", "dffd@bvfd.com"); + Mentor m1 = new Mentor("Anna Chernenko", "fvfdvfd@re.com", "docent"); + + + System.out.println(s1.getRole()); + System.out.println(s1.getName()); + System.out.println(s1.getEmail()); + System.out.println(s1.getSummary()); + System.out.println(m1.getRole()); +// System.out.println(m1.getAssignedCourses()); + System.out.println(m1.getName()); + System.out.println(m1.getSummary()); + System.out.println(m1.getExpertise()); + + + } } diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java index e8d7a4d..f37df0e 100644 --- a/task-1/com.hyfacademy/model/Course.java +++ b/task-1/com.hyfacademy/model/Course.java @@ -2,35 +2,45 @@ import com.hyfacademy.exception.AlreadyEnrolledException; import com.hyfacademy.exception.CourseFullException; +import com.hyfacademy.exception.EnrolmentException; +import com.hyfacademy.exception.InvalidProgressException; public abstract class Course { private final String courseName; private final String courseId; private int maxStudents; + private int enrolledCount = 0; - private int[] studentProgress = new int[maxStudents]; - private Student[] enrolledStudent = new Student[maxStudents]; + + private int[] studentProgress; + private Student[] enrolledStudent; + static int courseCounter = 0; public Course(String courseName, int maxStudents){ this.courseName = courseName; this.maxStudents = maxStudents; this.courseId = generateCourseId(); + + this.studentProgress = new int[maxStudents]; + this.enrolledStudent = new Student[maxStudents]; } public String getCourseName(){return courseName;} public int getMaxStudents(){return maxStudents;} public String getCourseId(){return courseId;} + 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 ); + return String.format("[%s] %s (%s) | Enrolled: %d/%d", + courseId, courseName, getCourseType(), enrolledCount, maxStudents ); } public void enrol(Student student){ - if(enrolledCount == maxStudents){ + if(isFull()){ throw new CourseFullException(courseName, maxStudents); } @@ -39,18 +49,46 @@ public void enrol(Student student){ throw new AlreadyEnrolledException(student.getName(), courseName); } } + student.enrol(this); + enrolledStudent[enrolledCount] = student; studentProgress[enrolledCount] = 0; + enrolledCount ++; } + public void updateProgress(Student student, int progress){ + if(progress < 0 || progress > 100){ + throw new InvalidProgressException(progress); + } + + for ( int i = 0; i < enrolledCount; i++){ + if(enrolledStudent[i].getUserId().equals(student.getUserId())){ + studentProgress[i] = progress; + return; + } + } + throw new EnrolmentException(String.format( + "%s doesn't enroll in course %s", student.getName(), courseName)); + } + + public int getStudentProgress(Student student) { + for (int i = 0; i < enrolledCount; i++) { + if (enrolledStudent[i].getUserId().equals(student.getUserId())) { + return studentProgress[i]; + } + } + throw new EnrolmentException(String.format( + "%s doesn't enroll in course %s", student.getName(), courseName)); + } + public boolean isFull(){ + return enrolledCount == maxStudents; + } public static String generateCourseId(){ courseCounter ++; return String.format("CRS-%03d", courseCounter); }; - - } diff --git a/task-1/com.hyfacademy/model/Student.java b/task-1/com.hyfacademy/model/Student.java index 2a43219..71f0a11 100644 --- a/task-1/com.hyfacademy/model/Student.java +++ b/task-1/com.hyfacademy/model/Student.java @@ -37,16 +37,15 @@ public void enrol(Course course){ courseCounter ++; } -// BACK AFTER COURSE CLASS CREATE! -// public String getProgress(String courseName){ -// for(Course c : enrolledCourses){ -// if(c != null && c.getCourseName.equals(courseName)){continue;} -// else{throw new EnrolmentException(String.format("%s doesn't enroll in '%s' course.", getName(), courseName));} -// } -// -// return String.format("%s progress in course '%s' equal to ", getName(), courseName) -// -// } + public int getProgress(String courseName){ + for(Course c : enrolledCourses) { + if (c != null && c.getCourseName().equals(courseName)) { + return c.getStudentProgress(this); + } + } + throw new EnrolmentException(String.format( + "%s doesn't enroll in '%s' course.", getName(), courseName)); + } public static String generateStudentId(){ studentCounter ++; From 4c64986822be40a81bb7e4bffaeb6853c466a1d4 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Wed, 13 May 2026 21:53:45 +0200 Subject: [PATCH 4/6] implement SelfPacedCourse class --- task-1/com.hyfacademy/Main.java | 23 +++---- task-1/com.hyfacademy/model/Course.java | 28 +++++++-- .../model/LiveCohortCourse.java | 37 +++++++++++- task-1/com.hyfacademy/model/Mentor.java | 4 +- .../com.hyfacademy/model/SelfPacedCourse.java | 60 ++++++++++++++++++- task-1/com.hyfacademy/model/Student.java | 2 +- task-1/com.hyfacademy/service/Enrollable.java | 13 +++- task-1/com.hyfacademy/service/Reportable.java | 3 +- 8 files changed, 149 insertions(+), 21 deletions(-) diff --git a/task-1/com.hyfacademy/Main.java b/task-1/com.hyfacademy/Main.java index d713980..5387ad9 100644 --- a/task-1/com.hyfacademy/Main.java +++ b/task-1/com.hyfacademy/Main.java @@ -2,6 +2,7 @@ import com.hyfacademy.model.Mentor; +import com.hyfacademy.model.SelfPacedCourse; import com.hyfacademy.model.Student; public class Main { @@ -10,17 +11,19 @@ public static void main(String[] args) { Student s1 = new Student("Alex Lirman", "dffd@bvfd.com"); Mentor m1 = new Mentor("Anna Chernenko", "fvfdvfd@re.com", "docent"); - - - System.out.println(s1.getRole()); - System.out.println(s1.getName()); - System.out.println(s1.getEmail()); - System.out.println(s1.getSummary()); - System.out.println(m1.getRole()); + SelfPacedCourse c1 = new SelfPacedCourse("Java Script", 20, 60); + s1.enrol(c1); + +// System.out.println(s1.getRole()); +// System.out.println(s1.getName()); +// System.out.println(s1.getEmail()); +// System.out.println(s1.getSummary()); +// System.out.println(m1.getRole()); // System.out.println(m1.getAssignedCourses()); - System.out.println(m1.getName()); - System.out.println(m1.getSummary()); - System.out.println(m1.getExpertise()); +// System.out.println(m1.getName()); +// System.out.println(m1.getSummary()); +// System.out.println(m1.getExpertise()); + System.out.println(c1.getCourseType()); diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java index f37df0e..a51c668 100644 --- a/task-1/com.hyfacademy/model/Course.java +++ b/task-1/com.hyfacademy/model/Course.java @@ -4,19 +4,22 @@ import com.hyfacademy.exception.CourseFullException; import com.hyfacademy.exception.EnrolmentException; import com.hyfacademy.exception.InvalidProgressException; +import com.hyfacademy.service.Enrollable; -public abstract class Course { +public abstract class Course implements Enrollable { private final String courseName; private final String courseId; - private int maxStudents; + private final int maxStudents; private int enrolledCount = 0; - private int[] studentProgress; - private Student[] enrolledStudent; + private final int[] studentProgress; + private final Student[] enrolledStudent; static int courseCounter = 0; + static final int BAR_BLOCKS = 10; + public Course(String courseName, int maxStudents){ this.courseName = courseName; this.maxStudents = maxStudents; @@ -29,6 +32,8 @@ public Course(String courseName, int maxStudents){ public String getCourseName(){return courseName;} public int getMaxStudents(){return maxStudents;} public String getCourseId(){return courseId;} + public int getEnrolledCount(){return enrolledCount;} + public Student[] getEnrolledStudent(){return enrolledStudent;} public abstract String getCourseType(); public abstract String getScheduleInfo(); @@ -87,6 +92,21 @@ public boolean isFull(){ return enrolledCount == maxStudents; } + public String getProgressBar(Student student){ + int filledBlocks = (int) Math.round(getStudentProgress(student) / 10.0); + + StringBuilder bar = new StringBuilder(); + + for(int i=0; i < BAR_BLOCKS; i++){ + if(i < filledBlocks){ + bar.append("█"); + } else { + bar.append("░"); + } + } + return bar.toString(); + } + public static String generateCourseId(){ courseCounter ++; return String.format("CRS-%03d", courseCounter); diff --git a/task-1/com.hyfacademy/model/LiveCohortCourse.java b/task-1/com.hyfacademy/model/LiveCohortCourse.java index a69fb63..6e15592 100644 --- a/task-1/com.hyfacademy/model/LiveCohortCourse.java +++ b/task-1/com.hyfacademy/model/LiveCohortCourse.java @@ -1,4 +1,39 @@ package com.hyfacademy.model; -public class LiveCohortCourse { +import com.hyfacademy.service.Reportable; + +public class LiveCohortCourse extends Course implements Reportable { + private final String startDate; + private final String endDate; + private Mentor mentor; + + public LiveCohortCourse(String courseName, int maxStudents, String startDate, String endDate){ + super(courseName, maxStudents); + this.startDate = startDate; + this.endDate = endDate; + } + + public String getStartDate(){return startDate;} + public String getEndDate(){return endDate;} + public Mentor getMentor(){return mentor;} + + @Override + public String getCourseType() { + return "Live Cohort"; + } + + @Override + public String getScheduleInfo(){ + return String.format("%s to %s | Mentor: %s", + startDate, endDate, mentor != null? mentor.getName() : "TBA"); + } + + public void assignMentor(Mentor mentor){ + this.mentor = mentor; + mentor.assignToCourse(this); + } + + public String generateReport() { + } + } diff --git a/task-1/com.hyfacademy/model/Mentor.java b/task-1/com.hyfacademy/model/Mentor.java index 72b0805..c6a3154 100644 --- a/task-1/com.hyfacademy/model/Mentor.java +++ b/task-1/com.hyfacademy/model/Mentor.java @@ -3,8 +3,8 @@ import com.hyfacademy.exception.EnrolmentException; public class Mentor extends User { - private String expertise; - private Course[] assignedCourses = new Course[3]; + private final String expertise; + private final Course[] assignedCourses = new Course[3]; private int courseCounter = 0; private static int mentorCounter = 0; diff --git a/task-1/com.hyfacademy/model/SelfPacedCourse.java b/task-1/com.hyfacademy/model/SelfPacedCourse.java index 055d64a..cc6268f 100644 --- a/task-1/com.hyfacademy/model/SelfPacedCourse.java +++ b/task-1/com.hyfacademy/model/SelfPacedCourse.java @@ -1,4 +1,62 @@ package com.hyfacademy.model; -public class SelfPacedCourse { +import com.hyfacademy.service.Enrollable; +import com.hyfacademy.service.Reportable; + +public class SelfPacedCourse extends Course implements Reportable { + private final int estimatedHours; + + public SelfPacedCourse(String courseName, int maxStudents, int estimateHours){ + super(courseName, maxStudents); + this.estimatedHours = estimateHours; + } + + public int getEstimateHours(){return 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 String generateReport() { + StringBuilder sb = new StringBuilder(); + + sb.append("══════════════════════════════════════════\n"); + sb.append(" COURSE REPORT — Self-Paced\n"); + sb.append("══════════════════════════════════════════\n"); + sb.append(String.format(" %-12s : %s%n", "ID", getCourseId())); + sb.append(String.format(" %-12s : %s%n", "Name", getCourseName())); + sb.append(String.format(" %-12s : %s%n", "Capacity", capacityStatus())); + sb.append(String.format(" %-12s : %s%n", "Est. Hours", estimatedHours)); + sb.append("──────────────────────────────────────────"); + sb.append(" STUDENT PROGRESS\n"); + sb.append("──────────────────────────────────────────"); + + for (int i=0; i < getEnrolledCount(); i++){ + Student s = getEnrolledStudent()[i]; + int progress = getStudentProgress(s); + + sb.append(String.format(" %-8s %-18s %3d%% %s%n", + s.getUserId(), s.getName(), progress, getProgressBar(s))); + } + + sb.append("──────────────────────────────────────────"); + + int totalStudentsProgress = 0; + for(int i=0; i < getEnrolledCount(); i++){ + Student[] students = getEnrolledStudent(); + totalStudentsProgress += getStudentProgress(students[i]); + } + double avgProgress = (double) totalStudentsProgress / getEnrolledCount(); + sb.append(String.format(" %-10s : %.2f%n", "Avg Progress", avgProgress)); + sb.append("══════════════════════════════════════════\n"); + + return sb.toString(); + } } diff --git a/task-1/com.hyfacademy/model/Student.java b/task-1/com.hyfacademy/model/Student.java index 71f0a11..fc6006f 100644 --- a/task-1/com.hyfacademy/model/Student.java +++ b/task-1/com.hyfacademy/model/Student.java @@ -4,7 +4,7 @@ import com.hyfacademy.exception.EnrolmentException; public class Student extends User { - private Course[] enrolledCourses = new Course[5]; + private final Course[] enrolledCourses = new Course[5]; private int courseCounter = 0; private static int studentCounter = 0; diff --git a/task-1/com.hyfacademy/service/Enrollable.java b/task-1/com.hyfacademy/service/Enrollable.java index a8151b7..2aeae7e 100644 --- a/task-1/com.hyfacademy/service/Enrollable.java +++ b/task-1/com.hyfacademy/service/Enrollable.java @@ -1,4 +1,15 @@ package com.hyfacademy.service; -public class Enrollable { +import com.hyfacademy.model.Student; + +public interface Enrollable { + void enrol(Student student); + boolean isFull(); + int getEnrolledCount(); + int getMaxStudents(); + + default String capacityStatus() { + return getEnrolledCount() + "/" + getMaxStudents() + + (isFull() ? " — FULL" : " — Open"); + } } diff --git a/task-1/com.hyfacademy/service/Reportable.java b/task-1/com.hyfacademy/service/Reportable.java index 0c8ae05..6acf8cd 100644 --- a/task-1/com.hyfacademy/service/Reportable.java +++ b/task-1/com.hyfacademy/service/Reportable.java @@ -1,4 +1,5 @@ package com.hyfacademy.service; -public class Reportable { +public interface Reportable { + String generateReport(); } From a9a8e8722832f95befcf18ca6f2a778309ae3c4a Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Thu, 14 May 2026 00:14:49 +0200 Subject: [PATCH 5/6] implement LiveCohortCourse class --- task-1/com.hyfacademy/model/Course.java | 24 +++++++++++++++++++ .../model/LiveCohortCourse.java | 20 ++++++++++++++++ .../com.hyfacademy/model/SelfPacedCourse.java | 24 ++++--------------- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java index a51c668..47ff9b8 100644 --- a/task-1/com.hyfacademy/model/Course.java +++ b/task-1/com.hyfacademy/model/Course.java @@ -107,6 +107,30 @@ public String getProgressBar(Student student){ return bar.toString(); } + public String studentReportListProgress(){ + StringBuilder sb = new StringBuilder(); + + for (int i=0; i < getEnrolledCount(); i++){ + Student s = getEnrolledStudent()[i]; + int progress = getStudentProgress(s); + + sb.append(String.format(" %-8s %-18s %3d%% %s%n", + s.getUserId(), s.getName(), progress, getProgressBar(s))); + } + + return sb.toString(); + } + + public double getAverageCourseProgress(){ + int totalStudentsProgress = 0; + for(int i=0; i < getEnrolledCount(); i++){ + Student[] students = getEnrolledStudent(); + totalStudentsProgress += getStudentProgress(students[i]); + } + + return (double) totalStudentsProgress / getEnrolledCount(); + } + public static String generateCourseId(){ courseCounter ++; return String.format("CRS-%03d", courseCounter); diff --git a/task-1/com.hyfacademy/model/LiveCohortCourse.java b/task-1/com.hyfacademy/model/LiveCohortCourse.java index 6e15592..df6df75 100644 --- a/task-1/com.hyfacademy/model/LiveCohortCourse.java +++ b/task-1/com.hyfacademy/model/LiveCohortCourse.java @@ -33,7 +33,27 @@ public void assignMentor(Mentor mentor){ mentor.assignToCourse(this); } + @Override public String generateReport() { + StringBuilder sb = new StringBuilder(); + + sb.append("══════════════════════════════════════════\n"); + sb.append(" COURSE REPORT — Live Cohort\n"); + sb.append("══════════════════════════════════════════\n"); + sb.append(String.format(" %-12s : %s%n", "ID", getCourseId())); + sb.append(String.format(" %-12s : %s%n", "Name", getCourseName())); + sb.append(String.format(" %-12s : %s to %s%n", "Schedule", startDate, endDate)); + sb.append(String.format(" %-12s : %s%n", "Mentor", mentor != null? mentor.getName() : "TBA" )); + sb.append(String.format(" %-12s : %s%n", "Capacity", capacityStatus())); + sb.append("──────────────────────────────────────────\n"); + sb.append(" STUDENT PROGRESS\n"); + sb.append("──────────────────────────────────────────\n"); + sb.append(studentReportListProgress()); + sb.append("──────────────────────────────────────────\n"); + sb.append(String.format(" %-10s : %.0f%%%n", "Avg Progress", getAverageCourseProgress())); + sb.append("══════════════════════════════════════════\n"); + + return sb.toString(); } } diff --git a/task-1/com.hyfacademy/model/SelfPacedCourse.java b/task-1/com.hyfacademy/model/SelfPacedCourse.java index cc6268f..3b2aa48 100644 --- a/task-1/com.hyfacademy/model/SelfPacedCourse.java +++ b/task-1/com.hyfacademy/model/SelfPacedCourse.java @@ -34,27 +34,13 @@ public String generateReport() { sb.append(String.format(" %-12s : %s%n", "Name", getCourseName())); sb.append(String.format(" %-12s : %s%n", "Capacity", capacityStatus())); sb.append(String.format(" %-12s : %s%n", "Est. Hours", estimatedHours)); - sb.append("──────────────────────────────────────────"); + sb.append("──────────────────────────────────────────\n"); sb.append(" STUDENT PROGRESS\n"); - sb.append("──────────────────────────────────────────"); + sb.append("──────────────────────────────────────────\n"); + sb.append(studentReportListProgress()); + sb.append("──────────────────────────────────────────\n"); - for (int i=0; i < getEnrolledCount(); i++){ - Student s = getEnrolledStudent()[i]; - int progress = getStudentProgress(s); - - sb.append(String.format(" %-8s %-18s %3d%% %s%n", - s.getUserId(), s.getName(), progress, getProgressBar(s))); - } - - sb.append("──────────────────────────────────────────"); - - int totalStudentsProgress = 0; - for(int i=0; i < getEnrolledCount(); i++){ - Student[] students = getEnrolledStudent(); - totalStudentsProgress += getStudentProgress(students[i]); - } - double avgProgress = (double) totalStudentsProgress / getEnrolledCount(); - sb.append(String.format(" %-10s : %.2f%n", "Avg Progress", avgProgress)); + sb.append(String.format(" %-10s : %.2f%%%n", "Avg Progress", getAverageCourseProgress())); sb.append("══════════════════════════════════════════\n"); return sb.toString(); From 2b39d0891c7bb351977c2fd0206b2f1468ebf5c8 Mon Sep 17 00:00:00 2001 From: Yana Pechenenko Date: Thu, 14 May 2026 18:18:32 +0200 Subject: [PATCH 6/6] finish with PlatformService --- task-1/com.hyfacademy/Main.java | 27 +- task-1/com.hyfacademy/model/Course.java | 21 +- task-1/com.hyfacademy/model/Mentor.java | 7 +- .../com.hyfacademy/model/SelfPacedCourse.java | 1 - task-1/com.hyfacademy/model/Student.java | 11 +- .../service/PlatformService.java | 387 ++++++++++++++++++ 6 files changed, 412 insertions(+), 42 deletions(-) diff --git a/task-1/com.hyfacademy/Main.java b/task-1/com.hyfacademy/Main.java index 5387ad9..4571fc2 100644 --- a/task-1/com.hyfacademy/Main.java +++ b/task-1/com.hyfacademy/Main.java @@ -1,31 +1,10 @@ package com.hyfacademy; - -import com.hyfacademy.model.Mentor; -import com.hyfacademy.model.SelfPacedCourse; -import com.hyfacademy.model.Student; +import com.hyfacademy.service.PlatformService; public class Main { public static void main(String[] args) { - - - Student s1 = new Student("Alex Lirman", "dffd@bvfd.com"); - Mentor m1 = new Mentor("Anna Chernenko", "fvfdvfd@re.com", "docent"); - SelfPacedCourse c1 = new SelfPacedCourse("Java Script", 20, 60); - s1.enrol(c1); - -// System.out.println(s1.getRole()); -// System.out.println(s1.getName()); -// System.out.println(s1.getEmail()); -// System.out.println(s1.getSummary()); -// System.out.println(m1.getRole()); -// System.out.println(m1.getAssignedCourses()); -// System.out.println(m1.getName()); -// System.out.println(m1.getSummary()); -// System.out.println(m1.getExpertise()); - System.out.println(c1.getCourseType()); - - - + PlatformService platformService = new PlatformService(); + platformService.run(); } } diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java index 47ff9b8..0e8c01a 100644 --- a/task-1/com.hyfacademy/model/Course.java +++ b/task-1/com.hyfacademy/model/Course.java @@ -10,15 +10,17 @@ public abstract class Course implements Enrollable { private final String courseName; private final String courseId; private final int maxStudents; + private final int[] studentProgress; + private final Student[] enrolledStudent; private int enrolledCount = 0; + private static int courseCounter = 0; - private final int[] studentProgress; - private final Student[] enrolledStudent; + private static final int BAR_BLOCKS = 10; + public static final int MIN_PROGRESS = 0; + public static final int MAX_PROGRESS = 100; - static int courseCounter = 0; - static final int BAR_BLOCKS = 10; public Course(String courseName, int maxStudents){ this.courseName = courseName; @@ -64,7 +66,7 @@ public void enrol(Student student){ } public void updateProgress(Student student, int progress){ - if(progress < 0 || progress > 100){ + if(progress < MIN_PROGRESS || progress > MAX_PROGRESS){ throw new InvalidProgressException(progress); } @@ -93,7 +95,7 @@ public boolean isFull(){ } public String getProgressBar(Student student){ - int filledBlocks = (int) Math.round(getStudentProgress(student) / 10.0); + int filledBlocks = (int) Math.round((float) getStudentProgress(student) / BAR_BLOCKS); StringBuilder bar = new StringBuilder(); @@ -114,7 +116,7 @@ public String studentReportListProgress(){ Student s = getEnrolledStudent()[i]; int progress = getStudentProgress(s); - sb.append(String.format(" %-8s %-18s %3d%% %s%n", + sb.append(String.format(" %-6s %-13s %3d%% %s%n", s.getUserId(), s.getName(), progress, getProgressBar(s))); } @@ -123,8 +125,11 @@ public String studentReportListProgress(){ public double getAverageCourseProgress(){ int totalStudentsProgress = 0; + + if (getEnrolledCount() == 0) return 0; + + Student[] students = getEnrolledStudent(); for(int i=0; i < getEnrolledCount(); i++){ - Student[] students = getEnrolledStudent(); totalStudentsProgress += getStudentProgress(students[i]); } diff --git a/task-1/com.hyfacademy/model/Mentor.java b/task-1/com.hyfacademy/model/Mentor.java index c6a3154..07fb928 100644 --- a/task-1/com.hyfacademy/model/Mentor.java +++ b/task-1/com.hyfacademy/model/Mentor.java @@ -3,10 +3,11 @@ import com.hyfacademy.exception.EnrolmentException; public class Mentor extends User { + private static final int MAX_ASSIGNED_COURSES = 3; private final String expertise; - private final Course[] assignedCourses = new Course[3]; - private int courseCounter = 0; + private final Course[] assignedCourses = new Course[MAX_ASSIGNED_COURSES]; + private int courseCounter = 0; private static int mentorCounter = 0; public Mentor(String name, String email, String expertise){ @@ -21,7 +22,7 @@ public Mentor(String name, String email, String expertise){ public String getRole(){return "MENTOR";} public void assignToCourse(Course course){ - if(courseCounter == 3){ + if(courseCounter == MAX_ASSIGNED_COURSES){ throw new EnrolmentException( String.format("Mentor %s cannot be assigned to more than 3 courses", getName()) ); diff --git a/task-1/com.hyfacademy/model/SelfPacedCourse.java b/task-1/com.hyfacademy/model/SelfPacedCourse.java index 3b2aa48..2aca932 100644 --- a/task-1/com.hyfacademy/model/SelfPacedCourse.java +++ b/task-1/com.hyfacademy/model/SelfPacedCourse.java @@ -1,6 +1,5 @@ package com.hyfacademy.model; -import com.hyfacademy.service.Enrollable; import com.hyfacademy.service.Reportable; public class SelfPacedCourse extends Course implements Reportable { diff --git a/task-1/com.hyfacademy/model/Student.java b/task-1/com.hyfacademy/model/Student.java index fc6006f..5fe4d56 100644 --- a/task-1/com.hyfacademy/model/Student.java +++ b/task-1/com.hyfacademy/model/Student.java @@ -4,9 +4,11 @@ import com.hyfacademy.exception.EnrolmentException; public class Student extends User { - private final Course[] enrolledCourses = new Course[5]; - private int courseCounter = 0; + private static final int MAX_ENROLLED_COURSES = 5; + + private final Course[] enrolledCourses = new Course[MAX_ENROLLED_COURSES]; + private int courseCounter = 0; private static int studentCounter = 0; public Student(String name, String email){ @@ -22,7 +24,7 @@ public String getRole(){ public int getCourseCount(){return courseCounter;} public void enrol(Course course){ - if(courseCounter == 5){ + if(courseCounter == MAX_ENROLLED_COURSES){ throw new EnrolmentException( String.format("%s own course list is full (5 courses max)", getName())); } @@ -51,7 +53,4 @@ public static String generateStudentId(){ studentCounter ++; return String.format("STU-%03d", studentCounter); } - - - } diff --git a/task-1/com.hyfacademy/service/PlatformService.java b/task-1/com.hyfacademy/service/PlatformService.java index 4248597..fee4d0f 100644 --- a/task-1/com.hyfacademy/service/PlatformService.java +++ b/task-1/com.hyfacademy/service/PlatformService.java @@ -1,4 +1,391 @@ package com.hyfacademy.service; + +import com.hyfacademy.exception.EnrolmentException; +import com.hyfacademy.model.*; + +import java.util.Scanner; + public class PlatformService { + private static final int MAX_COURSES = 10; + private static final int MAX_STUDENTS = 20; + private static final int MAX_MENTORS = 5; + + private final Course[] courses = new Course[MAX_COURSES]; + private final Student[] students = new Student[MAX_STUDENTS]; + private final Mentor[] mentors = new Mentor[MAX_MENTORS]; + + private static int courseCount = 0; + private static int studentCount = 0; + private static int mentorCount = 0; + + private final Scanner scanner = new Scanner(System.in); + + public void addCourse() { + if (courseCount == MAX_COURSES) { + System.out.printf("Cannot add more courses - limit reached(%d).%n", MAX_COURSES); + return; + } + + System.out.print("Select course type: \n1. Self paced course.\n2. Live cohort course.\nYour choice: "); + int type; + try { + type = scanner.nextInt(); + } catch (Exception e) { + System.out.println("Invalid input. Select 1 or 2."); + return; + } finally { + scanner.nextLine(); + } + + + if (type != 1 && type != 2) { + System.out.println("Invalid choice. Select 1 or 2."); + return; + } + + System.out.print("Please enter course name: "); + String courseName = scanner.nextLine(); + + + if (type == 1) { + System.out.print("Please enter estimate hours: "); + + if (!scanner.hasNextInt()) { + System.out.println("Invalid input. Hours must be a number."); + scanner.nextLine(); + return; + } + + int estimateHours = scanner.nextInt(); + scanner.nextLine(); + SelfPacedCourse spc1 = new SelfPacedCourse(courseName, MAX_STUDENTS, estimateHours); + courses[courseCount] = spc1; + courseCount++; + System.out.println("Self paced course successfully created!"); + } + + if (type == 2) { + System.out.print("Please enter start date: "); + String startDate = scanner.nextLine(); + if (!startDate.matches("\\d{4}-\\d{2}-\\d{2}")) { + System.out.println("Invalid date. Use format YYYY-MM-DD."); + return; + } + + System.out.print("Please enter end date: "); + String endDate = scanner.nextLine(); + if (!endDate.matches("\\d{4}-\\d{2}-\\d{2}")) { + System.out.println("Invalid date. Use format YYYY-MM-DD."); + return; + } + + LiveCohortCourse lcc1 = new LiveCohortCourse(courseName, MAX_STUDENTS, startDate, endDate); + courses[courseCount] = lcc1; + courseCount++; + System.out.println("Live cohort course successfully created!"); + } + + } + + public void addStudent() { + if (studentCount == MAX_STUDENTS) { + System.out.printf("Cannot add more students - limit reached(%d).%n", MAX_STUDENTS); + return; + } + + System.out.print("Please enter student name: "); + String studentName = scanner.nextLine(); + + if (!studentName.matches("[A-Za-z ]+")) { + System.out.println("Invalid name. Use letters only."); + return; + } + + System.out.print("Please enter student email: "); + String studentEmail = scanner.nextLine(); + + if (!studentEmail.contains("@")) { + System.out.println("Invalid email format."); + return; + } + + + Student s1 = new Student(studentName, studentEmail); + students[studentCount] = s1; + studentCount++; + System.out.println("Student successfully created!"); + + } + + public void addMentor() { + if (mentorCount == MAX_MENTORS) { + System.out.printf("Cannot add more mentors - limit reached(%d).%n", MAX_MENTORS); + return; + } + System.out.print("Please enter mentor name: "); + String mentorName = scanner.nextLine(); + + if (!mentorName.matches("[A-Za-z ]+")) { + System.out.println("Invalid name. Use letters only."); + return; + } + + System.out.print("Please enter mentor email: "); + String mentorEmail = scanner.nextLine(); + + if (!mentorEmail.contains("@")) { + System.out.println("Invalid email format."); + return; + } + + System.out.print("Please enter mentor expertise: "); + String mentorExpertise = scanner.nextLine(); + + Mentor m1 = new Mentor(mentorName, mentorEmail, mentorExpertise); + mentors[mentorCount] = m1; + mentorCount++; + System.out.println("Mentor successfully created!"); + } + + public void enrollStudent() { + System.out.print("Please enter student ID: "); + String studentId = scanner.nextLine(); + System.out.print("Please enter course ID: "); + String courseId = scanner.nextLine(); + + Student foundStudent = findStudentById(studentId); + Course foundCourse = findCourseById(courseId); + + if (isInvalid(foundStudent, foundCourse)) return; + + try { + foundCourse.enrol(foundStudent); + System.out.println("Student enrolled successfully!"); + } catch (EnrolmentException e) { + System.out.println("Error: " + e.getMessage()); + } + + } + + + public void updateProgress() { + System.out.print("Please enter student ID: "); + String studentId = scanner.nextLine(); + System.out.print("Please enter course ID: "); + String courseId = scanner.nextLine(); + + Student foundStudent = findStudentById(studentId); + Course foundCourse = findCourseById(courseId); + + if (isInvalid(foundStudent, foundCourse)) return; + + + System.out.print("Please enter progress value: "); + + if (!scanner.hasNextInt()) { + System.out.println("Invalid input. Progress must be a number between 0 and 100."); + scanner.nextLine(); + return; + } + + int progressValue = scanner.nextInt(); + scanner.nextLine(); + + + try { + foundCourse.updateProgress(foundStudent, progressValue); + System.out.println("Student progress updated successfully!"); + } catch (EnrolmentException e) { + System.out.println("Error: " + e.getMessage()); + } + + + } + + public void assignMentorToCourse() { + System.out.print("Enter mentor ID: "); + String mentorId = scanner.nextLine(); + + Mentor mentor = findMentorById(mentorId); + if (mentor == null) { + System.out.println("Mentor not found"); + return; + } + + System.out.print("Enter course ID: "); + String courseId = scanner.nextLine(); + + Course course = findCourseById(courseId); + if (course == null) { + System.out.println("Course not found"); + return; + } + + if (!(course instanceof LiveCohortCourse)) { + System.out.println("Only Live Cohort courses can have mentors."); + return; + } + + try { + ((LiveCohortCourse) course).assignMentor(mentor); + System.out.println("Mentor assigned successfully!"); + } catch (EnrolmentException e) { + System.out.println("Error: " + e.getMessage()); + } + } + + public String viewAllCourses(){ + if(courseCount == 0){ + return "No courses available."; + } + + StringBuilder sb = new StringBuilder(); + + sb.append("══════════════════════════════════════════════════════════════════\n"); + sb.append(String.format(" %-10s %-17s %-15s %-15s%n", "ID", "NAME", "TYPE", "CAPACITY")); + sb.append("══════════════════════════════════════════════════════════════════\n"); + + for (int i=0; i < courseCount; i++){ + Course c = courses[i]; + + sb.append(String.format(" %-10s %-17s %-15s %-15s%n", + c.getCourseId(), c.getCourseName(), c.getCourseType(), c.capacityStatus())); + } + + sb.append("══════════════════════════════════════════════════════════════════\n"); + +return sb.toString(); + + } + + public String viewCourseReport(){ + System.out.print("Enter course ID: "); + String courseId = scanner.nextLine(); + + Course course = findCourseById(courseId); + + if(course == null){ + return "Course not found"; + } + + if(!(course instanceof Reportable)){ + return "This course type does not support reports."; + } + + Reportable reportable = (Reportable) course; + + return reportable.generateReport(); + } + + public String viewAllStudents() { + if (studentCount == 0) { + return "No students available."; + } + + StringBuilder sb = new StringBuilder(); + + sb.append("══════════════════════════════════════════════════════════════════\n"); + sb.append(String.format(" %-10s %-17s %-15s %-10s%n", "ID", "NAME", "EMAIL", "COURSES")); + sb.append("══════════════════════════════════════════════════════════════════\n"); + + for (int i = 0; i < studentCount; i++) { + Student s = students[i]; + sb.append(String.format(" %-10s %-17s %-15s %5d%n", + s.getUserId(), s.getName(), s.getEmail(), s.getCourseCount())); + + } + + sb.append("══════════════════════════════════════════════════════════════════\n"); + return sb.toString(); + } + + public void run() { + while (true) { + System.out.println("╔══════════════════════════════════════════╗"); + System.out.println("║ HYF ACADEMY COURSE PLATFORM ║"); + System.out.println("╚══════════════════════════════════════════╝"); + System.out.println(" 1. Add course"); + System.out.println(" 2. Add student"); + System.out.println(" 3. Add mentor"); + System.out.println(" 4. Enrol student in course"); + System.out.println(" 5. Update student progress"); + System.out.println(" 6. Assign mentor to course"); + System.out.println(" 7. View all courses"); + System.out.println(" 8. View course report"); + System.out.println(" 9. View all students"); + System.out.println(" 10. Exit"); + System.out.println("══════════════════════════════════════════"); + System.out.print("Choose an option: "); + + if (!scanner.hasNextInt()) { + System.out.println("Invalid input. Choose between 1 and 10."); + scanner.nextLine(); + continue; + } + + int choice = scanner.nextInt(); + scanner.nextLine(); + + switch(choice){ + case 1 -> addCourse(); + case 2 -> addStudent(); + case 3 -> addMentor(); + case 4 -> enrollStudent(); + case 5 -> updateProgress(); + case 6 -> assignMentorToCourse(); + case 7 -> System.out.println(viewAllCourses()); + case 8 -> System.out.println(viewCourseReport()); + case 9 -> System.out.println(viewAllStudents()); + case 10 -> { + System.out.println("Goodbye!"); + scanner.close(); + return; + } + default -> System.out.println("Invalid option. Choose between 1 and 10."); + } + } + } + + + //helpers + + private Student findStudentById(String id) { + for (int i = 0; i < studentCount; i++) { + if (students[i].getUserId().equals(id)) { + return students[i]; + } + } + return null; + } + + private Course findCourseById(String id) { + for (int i = 0; i < courseCount; i++) { + if (courses[i].getCourseId().equals(id)) { + return courses[i]; + } + } + return null; + } + + private Mentor findMentorById(String id) { + for (int i = 0; i < mentorCount; i++) { + if (mentors[i].getUserId().equals(id)) { + return mentors[i]; + } + } + return null; + } + + private boolean isInvalid(Student s, Course c){ + if(s == null){ + System.out.println("Student not found"); + return true; + } + if(c == null){ + System.out.println("Course not found"); + return true; + } + return false; + } }