diff --git a/task-1/com.hyfacademy/Main.java b/task-1/com.hyfacademy/Main.java index d97363c..4571fc2 100644 --- a/task-1/com.hyfacademy/Main.java +++ b/task-1/com.hyfacademy/Main.java @@ -1,7 +1,10 @@ package com.hyfacademy; +import com.hyfacademy.service.PlatformService; + public class Main { - static void main(String[] args) { - System.out.println("Hello World!"); + public static void main(String[] args) { + PlatformService platformService = new PlatformService(); + platformService.run(); } } diff --git a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java b/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java index a82837e..10a035b 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 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;} } diff --git a/task-1/com.hyfacademy/exception/CourseFullException.java b/task-1/com.hyfacademy/exception/CourseFullException.java index 11a76f1..7334592 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 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;} } 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..5ded65d 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 final 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 diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java index e80513e..0e8c01a 100644 --- a/task-1/com.hyfacademy/model/Course.java +++ b/task-1/com.hyfacademy/model/Course.java @@ -1,4 +1,143 @@ package com.hyfacademy.model; -public class Course { +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 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 static final int BAR_BLOCKS = 10; + public static final int MIN_PROGRESS = 0; + public static final int MAX_PROGRESS = 100; + + + + 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 int getEnrolledCount(){return enrolledCount;} + public Student[] getEnrolledStudent(){return enrolledStudent;} + + 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(isFull()){ + 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 void updateProgress(Student student, int progress){ + if(progress < MIN_PROGRESS || progress > MAX_PROGRESS){ + 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 String getProgressBar(Student student){ + int filledBlocks = (int) Math.round((float) getStudentProgress(student) / BAR_BLOCKS); + + StringBuilder bar = new StringBuilder(); + + for(int i=0; i < BAR_BLOCKS; i++){ + if(i < filledBlocks){ + bar.append("█"); + } else { + bar.append("░"); + } + } + 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(" %-6s %-13s %3d%% %s%n", + s.getUserId(), s.getName(), progress, getProgressBar(s))); + } + + return sb.toString(); + } + + public double getAverageCourseProgress(){ + int totalStudentsProgress = 0; + + if (getEnrolledCount() == 0) return 0; + + Student[] students = getEnrolledStudent(); + for(int i=0; i < getEnrolledCount(); i++){ + 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 a69fb63..df6df75 100644 --- a/task-1/com.hyfacademy/model/LiveCohortCourse.java +++ b/task-1/com.hyfacademy/model/LiveCohortCourse.java @@ -1,4 +1,59 @@ 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); + } + + @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/Mentor.java b/task-1/com.hyfacademy/model/Mentor.java index b8738d5..07fb928 100644 --- a/task-1/com.hyfacademy/model/Mentor.java +++ b/task-1/com.hyfacademy/model/Mentor.java @@ -1,4 +1,46 @@ package com.hyfacademy.model; -public class Mentor { +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[MAX_ASSIGNED_COURSES]; + + 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 == MAX_ASSIGNED_COURSES){ + 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/SelfPacedCourse.java b/task-1/com.hyfacademy/model/SelfPacedCourse.java index 055d64a..2aca932 100644 --- a/task-1/com.hyfacademy/model/SelfPacedCourse.java +++ b/task-1/com.hyfacademy/model/SelfPacedCourse.java @@ -1,4 +1,47 @@ package com.hyfacademy.model; -public class SelfPacedCourse { +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("──────────────────────────────────────────\n"); + sb.append(" STUDENT PROGRESS\n"); + sb.append("──────────────────────────────────────────\n"); + sb.append(studentReportListProgress()); + sb.append("──────────────────────────────────────────\n"); + + sb.append(String.format(" %-10s : %.2f%%%n", "Avg Progress", getAverageCourseProgress())); + 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 9f34d88..5fe4d56 100644 --- a/task-1/com.hyfacademy/model/Student.java +++ b/task-1/com.hyfacademy/model/Student.java @@ -1,4 +1,56 @@ package com.hyfacademy.model; -public class Student { +import com.hyfacademy.exception.AlreadyEnrolledException; +import com.hyfacademy.exception.EnrolmentException; + +public class Student extends User { + 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){ + 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 == MAX_ENROLLED_COURSES){ + 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 ++; + } + + 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 ++; + 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(); + } + } 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/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; + } } 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(); }