93 lines
3.5 KiB
Java
93 lines
3.5 KiB
Java
package CourseRegistrationStarter;
|
|
import java.util.Scanner;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) {
|
|
|
|
Course c1 = new Course("Advanced Programming", "AP1404", 2);
|
|
Course c2 = new Course("Data Structures", "DS2201", 1);
|
|
Course c3 = new Course("Database Systems", "DB3301", 3);
|
|
Course c4 = new Course("Basics of Programming", "BP4041", 0);
|
|
|
|
RegistrationSystem system = new RegistrationSystem();
|
|
system.addCourseToSystem(c1);
|
|
system.addCourseToSystem(c2);
|
|
system.addCourseToSystem(c3);
|
|
system.addCourseToSystem(c3);
|
|
system.addCourseToSystem(c4);
|
|
|
|
|
|
|
|
Student student = new Student("Soroush", "404222000");
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
while (true) {
|
|
System.out.println("\n===== Course Registration Menu =====");
|
|
System.out.println("1. Show all courses");
|
|
System.out.println("2. Register course");
|
|
System.out.println("3. Drop course");
|
|
System.out.println("4. Show my courses");
|
|
System.out.println("5. Search course by name");
|
|
System.out.println("6. Exit");
|
|
System.out.print("Choose an option: ");
|
|
|
|
int choice = scanner.nextInt();
|
|
scanner.nextLine();
|
|
|
|
if (choice == 1) {
|
|
system.showAllCourses();
|
|
}
|
|
else if (choice == 2) {
|
|
System.out.print("Enter course code to register: ");
|
|
String code = scanner.nextLine();
|
|
Course course = system.findCourseByCode(code);
|
|
if (course == null) {
|
|
System.out.print("Course not found.");
|
|
} else {
|
|
student.addCourse(course);
|
|
}
|
|
}
|
|
else if (choice == 3) {
|
|
System.out.print("Enter course code to drop: ");
|
|
String code = scanner.nextLine();
|
|
Course course = system.findCourseByCode(code);
|
|
if (course == null) {
|
|
System.out.print("Course not found.");
|
|
} else {
|
|
student.dropCourse(course);
|
|
}
|
|
}
|
|
else if (choice == 4) {
|
|
student.showRegisteredCourses();
|
|
}
|
|
else if (choice == 5) {
|
|
System.out.print("Enter course name to search: ");
|
|
String name = scanner.nextLine();
|
|
Course course = system.findCourseByName(name);
|
|
if (course == null) {
|
|
System.out.println("Course not found.");
|
|
} else {
|
|
//boolean isRegistered = false;
|
|
//for (int i = 0; i < student.registeredCourses.size(); i++) {
|
|
// if (student.registeredCourses.get(i).getCourseCode().equals(course.getCourseCode())) {
|
|
// isRegistered = true;
|
|
// break;
|
|
// }
|
|
//}
|
|
System.out.println("Course found: " + course.getCourseName() + " (" + course.getCourseCode() + ") - Remaining capacity: " + course.getCapacity());
|
|
//System.out.println("Status: " + (isRegistered ? "Registered" : "Not Registered"));
|
|
}
|
|
}
|
|
else if (choice == 6) {
|
|
System.out.println("Exiting...");
|
|
break;
|
|
}
|
|
else {
|
|
System.out.println("Invalid choice.");
|
|
}
|
|
}
|
|
scanner.close();
|
|
}
|
|
}
|