From 4337dad762d9b98f4b8f68c3c7ff6ec2d07d78bf Mon Sep 17 00:00:00 2001 From: Saeed Jamali Date: Mon, 27 Apr 2026 14:11:57 +0330 Subject: [PATCH] add menu for the program --- src/CourseRegistrationStarter/Main.java | 84 ++++++++++++++++++- .../RegistrationSystem.java | 2 +- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/CourseRegistrationStarter/Main.java b/src/CourseRegistrationStarter/Main.java index de6db0c..e6a7d3f 100644 --- a/src/CourseRegistrationStarter/Main.java +++ b/src/CourseRegistrationStarter/Main.java @@ -1,7 +1,11 @@ package CourseRegistrationStarter; +import java.util.ArrayList; +import java.util.Scanner; + public class Main { public static void main(String[] args) { + ArrayList students= new ArrayList<>(); // TODO: Course BP = new Course("Basic Programming", "BP1404", 3); Course AP = new Course("Advanced Programming", "AP1405", 2); @@ -12,7 +16,6 @@ public class Main { register.addCourseToSystem(BP); register.addCourseToSystem(AP); register.addCourseToSystem(DS); - saeedJam.addCourse(AP); saeedJam.addCourse(DS); saeedJam.dropCourse(DS); @@ -24,5 +27,84 @@ public class Main { // 5. Register the student in some courses // 6. Drop one course // 7. Print the final registered course list + int command = 100; + Scanner scanner = new Scanner(System.in); + while (command != 0) { + if (command == 1) { + String courseName = ""; + String courseCode = ""; + int courseCapacity = 0; + System.out.println("Please enter course name: "); + courseName = scanner.nextLine(); + System.out.println("Enter course code: "); + courseCode = scanner.nextLine(); + System.out.println("Enter course capacity: "); + courseCapacity = scanner.nextInt(); + scanner.nextLine(); + register.addCourseToSystem(new Course(courseName, courseCode, courseCapacity)); + System.out.println("Course added successfully."); + + } else if (command == 2) { + String studentName = ""; + String studentId = ""; + System.out.println("Please enter student name: "); + studentName = scanner.nextLine(); + System.out.println("Enter student ID: "); + studentId = scanner.nextLine(); + students.add(new Student(studentName, studentId)); + System.out.println("Student added successfully."); + + } else if (command == 3) { + String studentId = ""; + String courseCode = ""; + Student studentToAdd; + System.out.println("Please enter student ID: "); + studentId = scanner.nextLine(); + System.out.println("Enter course code: "); + courseCode = scanner.nextLine(); + studentToAdd = null; + studentToAdd = findStudentById(students, studentId); + Course courseToAdd = register.findCourseByCode(courseCode); + studentToAdd.addCourse(courseToAdd); + System.out.println("Course "+ courseCode + " added successfuly for Student " + studentId); + + } else if (command == 4) { + String studentId = ""; + Student studentToShow = null; + System.out.println("Please enter student ID: "); + studentId = scanner.nextLine(); + studentToShow = findStudentById(students, studentId); + studentToShow.showRegisteredCourses(); + } else if (command == 5) { + String courseCode = ""; + System.out.println("Enter course code: "); + courseCode = scanner.nextLine(); + Course courseToShow = register.findCourseByCode(courseCode); + System.out.println(courseToShow.getCourseName() + ", Code: " + + courseToShow.getCourseCode() + ", Capacity: " + courseToShow.getCapacity()); + } else if (command == 6) { + register.showAllCourses(); + } + System.out.println("----------------MENU----------------"); + System.out.println("1-Add course to system"); + System.out.println("2-Add student"); + System.out.println("3-Add course for student"); + System.out.println("4-Show student courses"); + System.out.println("5-Find course by code"); + System.out.println("6-Show all courses"); + System.out.println("0-Exit\n"); + command = scanner.nextInt(); + scanner.nextLine(); + } } + + public static Student findStudentById(ArrayList studentList, String id) { + for (Student s: studentList) { + if (s.getStudentId().equals(id)) { + return s; + } + } + return null; + } + } diff --git a/src/CourseRegistrationStarter/RegistrationSystem.java b/src/CourseRegistrationStarter/RegistrationSystem.java index 1c520f0..82be031 100644 --- a/src/CourseRegistrationStarter/RegistrationSystem.java +++ b/src/CourseRegistrationStarter/RegistrationSystem.java @@ -26,7 +26,7 @@ public class RegistrationSystem { public void showAllCourses() { for(Course c: this.courses) { - System.out.println(c.getCourseName() + ", code: " + c.getCourseCode()); + System.out.println(c.getCourseName() + ", code: " + c.getCourseCode() + ", capacity: " + c.getCapacity()); } // TODO: Print all courses in the system }