diff --git a/.gitignore b/.gitignore index 2b76d7c..1c26682 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,12 @@ dist vite.config.js.timestamp-* vite.config.ts.timestamp-* + + +# Java compiled files +*.class + +# Package Files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/task-1/com.hyfacademy/Main.java b/task-1/com.hyfacademy/Main.java deleted file mode 100644 index d97363c..0000000 --- a/task-1/com.hyfacademy/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.hyfacademy; - -public class Main { - static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java b/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java deleted file mode 100644 index a82837e..0000000 --- a/task-1/com.hyfacademy/exception/AlreadyEnrolledException.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.exception; - -public class AlreadyEnrolledException { -} diff --git a/task-1/com.hyfacademy/exception/CourseFullException.java b/task-1/com.hyfacademy/exception/CourseFullException.java deleted file mode 100644 index 11a76f1..0000000 --- a/task-1/com.hyfacademy/exception/CourseFullException.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.exception; - -public class CourseFullException { -} diff --git a/task-1/com.hyfacademy/exception/EnrolmentException.java b/task-1/com.hyfacademy/exception/EnrolmentException.java deleted file mode 100644 index 8454c32..0000000 --- a/task-1/com.hyfacademy/exception/EnrolmentException.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.exception; - -public class EnrolmentException { -} diff --git a/task-1/com.hyfacademy/exception/InvalidProgressException.java b/task-1/com.hyfacademy/exception/InvalidProgressException.java deleted file mode 100644 index c0c0037..0000000 --- a/task-1/com.hyfacademy/exception/InvalidProgressException.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.exception; - -public class InvalidProgressException { -} diff --git a/task-1/com.hyfacademy/model/Course.java b/task-1/com.hyfacademy/model/Course.java deleted file mode 100644 index e80513e..0000000 --- a/task-1/com.hyfacademy/model/Course.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.model; - -public class Course { -} diff --git a/task-1/com.hyfacademy/model/LiveCohortCourse.java b/task-1/com.hyfacademy/model/LiveCohortCourse.java deleted file mode 100644 index a69fb63..0000000 --- a/task-1/com.hyfacademy/model/LiveCohortCourse.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.model; - -public class LiveCohortCourse { -} diff --git a/task-1/com.hyfacademy/model/Mentor.java b/task-1/com.hyfacademy/model/Mentor.java deleted file mode 100644 index b8738d5..0000000 --- a/task-1/com.hyfacademy/model/Mentor.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.model; - -public class Mentor { -} diff --git a/task-1/com.hyfacademy/model/SelfPacedCourse.java b/task-1/com.hyfacademy/model/SelfPacedCourse.java deleted file mode 100644 index 055d64a..0000000 --- a/task-1/com.hyfacademy/model/SelfPacedCourse.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.model; - -public class SelfPacedCourse { -} diff --git a/task-1/com.hyfacademy/model/Student.java b/task-1/com.hyfacademy/model/Student.java deleted file mode 100644 index 9f34d88..0000000 --- a/task-1/com.hyfacademy/model/Student.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.model; - -public class Student { -} diff --git a/task-1/com.hyfacademy/model/User.java b/task-1/com.hyfacademy/model/User.java deleted file mode 100644 index 43cba56..0000000 --- a/task-1/com.hyfacademy/model/User.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.model; - -public class User { -} diff --git a/task-1/com.hyfacademy/service/Enrollable.java b/task-1/com.hyfacademy/service/Enrollable.java deleted file mode 100644 index a8151b7..0000000 --- a/task-1/com.hyfacademy/service/Enrollable.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.service; - -public class Enrollable { -} diff --git a/task-1/com.hyfacademy/service/PlatformService.java b/task-1/com.hyfacademy/service/PlatformService.java deleted file mode 100644 index 4248597..0000000 --- a/task-1/com.hyfacademy/service/PlatformService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.service; - -public class PlatformService { -} diff --git a/task-1/com.hyfacademy/service/Reportable.java b/task-1/com.hyfacademy/service/Reportable.java deleted file mode 100644 index 0c8ae05..0000000 --- a/task-1/com.hyfacademy/service/Reportable.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.hyfacademy.service; - -public class Reportable { -} diff --git a/task-1/com/hyfacademy/Main.java b/task-1/com/hyfacademy/Main.java new file mode 100644 index 0000000..525ef8c --- /dev/null +++ b/task-1/com/hyfacademy/Main.java @@ -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(); + } +} \ No newline at end of file diff --git a/task-1/com/hyfacademy/exception/AlreadyEnrolledException.java b/task-1/com/hyfacademy/exception/AlreadyEnrolledException.java new file mode 100644 index 0000000..90a1120 --- /dev/null +++ b/task-1/com/hyfacademy/exception/AlreadyEnrolledException.java @@ -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; + } +} diff --git a/task-1/com/hyfacademy/exception/CourseFullException.java b/task-1/com/hyfacademy/exception/CourseFullException.java new file mode 100644 index 0000000..f103ede --- /dev/null +++ b/task-1/com/hyfacademy/exception/CourseFullException.java @@ -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; + } +} diff --git a/task-1/com/hyfacademy/exception/EnrolmentException.java b/task-1/com/hyfacademy/exception/EnrolmentException.java new file mode 100644 index 0000000..9f9af84 --- /dev/null +++ b/task-1/com/hyfacademy/exception/EnrolmentException.java @@ -0,0 +1,7 @@ +package com.hyfacademy.exception; + +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 new file mode 100644 index 0000000..f449264 --- /dev/null +++ b/task-1/com/hyfacademy/exception/InvalidProgressException.java @@ -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; + } +} diff --git a/task-1/com/hyfacademy/model/Course.java b/task-1/com/hyfacademy/model/Course.java new file mode 100644 index 0000000..8ce5a56 --- /dev/null +++ b/task-1/com/hyfacademy/model/Course.java @@ -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 0) ? total / enrolledCount : 0; + + System.out.println("──────────────────────────────────────────"); + System.out.println(" Avg Progress : " + avg + "%"); + System.out.println("══════════════════════════════════════════"); + } + + +} diff --git a/task-1/com/hyfacademy/model/LiveCohortCourse.java b/task-1/com/hyfacademy/model/LiveCohortCourse.java new file mode 100644 index 0000000..4ea4005 --- /dev/null +++ b/task-1/com/hyfacademy/model/LiveCohortCourse.java @@ -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(); + + } +} diff --git a/task-1/com/hyfacademy/model/Mentor.java b/task-1/com/hyfacademy/model/Mentor.java new file mode 100644 index 0000000..b0f7886 --- /dev/null +++ b/task-1/com/hyfacademy/model/Mentor.java @@ -0,0 +1,56 @@ +package com.hyfacademy.model; + +import com.hyfacademy.exception.EnrolmentException; + +public class Mentor extends User { + + private final String expertise; + private Course[] assignedCourses = new Course[3]; + private int courseCount = 0; + private static int totalMentors = 0; + + + public Mentor(String name, String email, String expertise) { + super(name, email, generateId()); + this.expertise = expertise; + totalMentors++; + } + + private static String generateId(){ + int id = totalMentors + 1; + if (id >= 100) { + return "COA-" + id; + } else if (id >= 10) { + return "COA-0" + id; + } else { + return "COA-00" + id; + } + } + + @Override + public String getRole() { + return "MENTOR"; + } + + public void assignToCourse(Course course) { + // throws EnrolmentException if already at max (3 courses) + if (courseCount >= 3) { + throw new EnrolmentException("Mentor " + getName() + " has reached the maximum limit of 3 courses."); + } + assignedCourses[courseCount] = course; + courseCount++; + } + + public Course[] getAssignedCourses(){ + // returns assigned courses + return assignedCourses; + } + + public String getExpertise() { + return expertise; + } + + public int getCourseCount() { + return courseCount; + } +} diff --git a/task-1/com/hyfacademy/model/SelfPacedCourse.java b/task-1/com/hyfacademy/model/SelfPacedCourse.java new file mode 100644 index 0000000..85b81c9 --- /dev/null +++ b/task-1/com/hyfacademy/model/SelfPacedCourse.java @@ -0,0 +1,35 @@ +package com.hyfacademy.model; + +import com.hyfacademy.service.Reportable; + +public class SelfPacedCourse extends Course implements Reportable { + public int estimatedHours; + + public SelfPacedCourse(String courseName, int maxStudents, int estimatedHours) { + super(courseName, maxStudents); + this.estimatedHours = estimatedHours; + } + + @Override + public String getCourseType() { + return "Self-Paced"; + } + + @Override + public String getScheduleInfo() { + return "Estimated: "+ estimatedHours +" hours — complete at your own pace"; + } + + @Override + public void generateReport() { + System.out.println("══════════════════════════════════════════"); + System.out.println(" COURSE REPORT — Self-Paced"); + System.out.println("══════════════════════════════════════════"); + System.out.println(" ID : " + getCourseId()); + System.out.println(" Name : " + getCourseName()); + System.out.println(" Capacity : " + capacityStatus()); + System.out.println(" Est. Hours : " + estimatedHours); + + printStudentsTable(); + } +} diff --git a/task-1/com/hyfacademy/model/Student.java b/task-1/com/hyfacademy/model/Student.java new file mode 100644 index 0000000..9813138 --- /dev/null +++ b/task-1/com/hyfacademy/model/Student.java @@ -0,0 +1,69 @@ +package com.hyfacademy.model; + +import com.hyfacademy.exception.AlreadyEnrolledException; +import com.hyfacademy.exception.EnrolmentException; + +public class Student extends User { + + private static int totalStudents; + private Course[] enrolledCourses = new Course[5]; + private int courseCount; + + public Student(String name, String email) { + super(name, email, generateId()); + totalStudents++; + } + + private static String generateId(){ + int id = totalStudents + 1; + if (id >= 100) { + return "STU-" + id; + } else if (id >= 10) { + return "STU-0" + id; + } else { + return "STU-00" + id; + } + } + + @Override + public String getRole() { + return "STUDENT"; + } + + + public void enrol(Course course) { + // adds to enrolledCourses; throws AlreadyEnrolledException if already enrolled, EnrolmentException if the student's own course list is full (5 courses max) + for (int i = 0; i < courseCount; i++) { + if (enrolledCourses[i].getCourseId().equals(course.getCourseId())) { + throw new AlreadyEnrolledException(this.getName(), course.getCourseName()); + } + } + + if (courseCount >= 5) { + throw new EnrolmentException("Student's enrolment limit reached (max: 5 courses)"); + } + + enrolledCourses[courseCount] = course; + courseCount++; + } + + public Course[] getCourses() { + return enrolledCourses; + } + + public int getCourseCount() { + return courseCount; + } + + + public int getProgress(String courseName) { + // returns the student's progress in that course (0–100); throws EnrolmentException if not enrolled + for (int i = 0; i < courseCount; i++) { + if (enrolledCourses[i].getCourseName().equals(courseName)) { + + return enrolledCourses[i].getStudentProgress(this); + } + } + throw new EnrolmentException( getName() + " is not enrolled in course: " + courseName); + } +} \ No newline at end of file diff --git a/task-1/com/hyfacademy/model/User.java b/task-1/com/hyfacademy/model/User.java new file mode 100644 index 0000000..7dcf6c9 --- /dev/null +++ b/task-1/com/hyfacademy/model/User.java @@ -0,0 +1,37 @@ +package com.hyfacademy.model; + +public abstract class User { + private String name; + private String email; + private 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 "["+ getRole() +"] "+ 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 new file mode 100644 index 0000000..25d863e --- /dev/null +++ b/task-1/com/hyfacademy/service/Enrollable.java @@ -0,0 +1,15 @@ +package com.hyfacademy.service; + +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"); + } +} \ No newline at end of file diff --git a/task-1/com/hyfacademy/service/PlatformService.java b/task-1/com/hyfacademy/service/PlatformService.java new file mode 100644 index 0000000..ade9784 --- /dev/null +++ b/task-1/com/hyfacademy/service/PlatformService.java @@ -0,0 +1,199 @@ +package com.hyfacademy.service; + +import com.hyfacademy.model.*; +import com.hyfacademy.exception.*; +import java.util.Scanner; + +public class PlatformService { + private Course[] courses = new Course[10]; + private int courseCount = 0; + private Student[] students = new Student[20]; + private int studentCount = 0; + private Mentor[] mentors = new Mentor[5]; + private int mentorCount = 0; + + private final Scanner scanner = new Scanner(System.in); + + public void run() { + boolean running = true; + while (running) { + System.out.println("\n╔══════════════════════════════════════════╗"); + 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. View all courses"); + System.out.println(" 7. View course report"); + System.out.println(" 8. View all students"); + System.out.println(" 9. Exit"); + System.out.println("══════════════════════════════════════════"); + System.out.print("Choose an option: "); + + String choice = scanner.nextLine(); + switch (choice) { + case "1" -> addCourse(); + case "2" -> addStudent(); + case "3" -> addMentor(); + case "4" -> enrolStudent(); + case "5" -> updateProgress(); + case "6" -> viewAllCourses(); + case "7" -> viewCourseReport(); + case "8" -> viewAllStudents(); + case "9" -> { + System.out.println("Exiting... Goodbye!"); + running = false; + } + default -> System.out.println("Invalid option, please try again."); + } + } + } + + private void addCourse() { + if (courseCount >= courses.length) { + System.out.println("Error: Maximum course capacity reached."); + return; + } + System.out.print("Course type (1: Self-Paced, 2: Live Cohort): "); + String type = scanner.nextLine(); + System.out.print("Course Name: "); + String name = scanner.nextLine(); + System.out.print("Capacity: "); + int capacity = Integer.parseInt(scanner.nextLine()); + + if (type.equals("1")) { + System.out.print("Estimated Hours: "); + int hours = Integer.parseInt(scanner.nextLine()); + courses[courseCount++] = new SelfPacedCourse(name, capacity, hours); + } else { + System.out.print("Start Date (YYYY-MM-DD): "); + String start = scanner.nextLine(); + System.out.print("End Date (YYYY-MM-DD): "); + String end = scanner.nextLine(); + courses[courseCount++] = new LiveCohortCourse(name, capacity, start, end); + } + System.out.println("Course added successfully."); + } + + private void addStudent() { + if (studentCount >= students.length) { + System.out.println("Error: Maximum student capacity reached."); + return; + } + System.out.print("Student Name: "); + String name = scanner.nextLine(); + System.out.print("Student Email: "); + String email = scanner.nextLine(); + students[studentCount++] = new Student(name, email); + System.out.println("Student registered successfully."); + } + + private void addMentor() { + if (mentorCount >= mentors.length) { + System.out.println("Error: Maximum mentor capacity reached."); + return; + } + System.out.print("Mentor Name: "); + String name = scanner.nextLine(); + System.out.print("Mentor Email: "); + String email = scanner.nextLine(); + System.out.print("Expertise: "); + String expertise = scanner.nextLine(); + mentors[mentorCount++] = new Mentor(name, email, expertise); + System.out.println("Mentor added successfully."); + } + + private void enrolStudent() { + try { + System.out.print("Enter Student ID: "); + String studentId = scanner.nextLine(); + System.out.print("Enter Course ID: "); + String courseId = scanner.nextLine(); + + Student student = findStudent(studentId); + Course course = findCourse(courseId); + + if (student != null && course != null) { + course.enrol(student); + System.out.println("Enrolment successful."); + } else { + System.out.println("Error: Student or Course not found."); + } + } catch (EnrolmentException e) { + System.out.println("Enrolment Error: " + e.getMessage()); + } + } + + private void updateProgress() { + try { + System.out.print("Enter Student ID: "); + String studentId = scanner.nextLine(); + System.out.print("Enter Course ID: "); + String courseId = scanner.nextLine(); + System.out.print("Progress (0-100): "); + int p = Integer.parseInt(scanner.nextLine()); + + Student student = findStudent(studentId); + Course course = findCourse(courseId); + + if (student != null && course != null) { + course.updateProgress(student, p); + System.out.println("Progress updated successfully."); + } else { + System.out.println("Error: Student or Course not found."); + } + } catch (Exception e) { + System.out.println("Update Error: " + e.getMessage()); + } + } + + private void viewAllCourses() { + if (courseCount == 0) { + System.out.println("No courses available."); + return; + } + for (int i = 0; i < courseCount; i++) { + System.out.println(courses[i].toString()); + } + } + + private void viewCourseReport() { + System.out.print("Enter Course ID: "); + String courseId = scanner.nextLine(); + Course course = findCourse(courseId); + + if (course == null) { + System.out.println("Error: Course not found."); + return; + } + + ((Reportable) course).generateReport(); + } + + private void viewAllStudents() { + if (studentCount == 0) { + System.out.println("No students registered."); + return; + } + for (int i = 0; i < studentCount; i++) { + System.out.println(students[i].getUserId() + " - " + students[i].getName()); + } + } + + private Student findStudent(String id) { + for (int i = 0; i < studentCount; i++) { + if (students[i].getUserId().equalsIgnoreCase(id)) return students[i]; + } + return null; + } + + private Course findCourse(String id) { + for (int i = 0; i < courseCount; i++) { + if (courses[i].getCourseId().equalsIgnoreCase(id)) return courses[i]; + } + return null; + } + +} \ No newline at end of file diff --git a/task-1/com/hyfacademy/service/Reportable.java b/task-1/com/hyfacademy/service/Reportable.java new file mode 100644 index 0000000..ed5de27 --- /dev/null +++ b/task-1/com/hyfacademy/service/Reportable.java @@ -0,0 +1,5 @@ +package com.hyfacademy.service; + +public interface Reportable { + void generateReport(); +} \ No newline at end of file