Workshop-2
This commit is contained in:
@@ -1,14 +1,92 @@
|
||||
package CourseRegistrationStarter;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO:
|
||||
// 1. Create at least 3 courses
|
||||
// 2. Create 1 student
|
||||
// 3. Create a registration system
|
||||
// 4. Add courses to the system
|
||||
// 5. Register the student in some courses
|
||||
// 6. Drop one course
|
||||
// 7. Print the final registered course list
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user