-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseRegistrationSystem.java
More file actions
129 lines (114 loc) · 4.38 KB
/
CourseRegistrationSystem.java
File metadata and controls
129 lines (114 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.util.Scanner;
public class CourseRegistrationSystem {
private CourseDatabase courseDatabase;
private StudentDatabase studentDatabase;
private Scanner scanner;
public CourseRegistrationSystem() {
courseDatabase = new CourseDatabase();
studentDatabase = new StudentDatabase();
scanner = new Scanner(System.in);
}
public void run() {
boolean running = true;
while (running) {
System.out.println("1. Add Course");
System.out.println("2. Add Student");
System.out.println("3. Register Course");
System.out.println("4. Drop Course");
System.out.println("5. List Courses");
System.out.println("6. List Students");
System.out.println("7. Exit");
System.out.print("Select an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
addCourse();
break;
case 2:
addStudent();
break;
case 3:
registerCourse();
break;
case 4:
dropCourse();
break;
case 5:
courseDatabase.listCourses();
break;
case 6:
studentDatabase.listStudents();
break;
case 7:
running = false;
break;
default:
System.out.println("Invalid option. Please try again.");
}
}
}
private void addCourse() {
System.out.print("Course Code: ");
String courseCode = scanner.nextLine();
System.out.print("Title: ");
String title = scanner.nextLine();
System.out.print("Description: ");
String description = scanner.nextLine();
System.out.print("Capacity: ");
int capacity = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Schedule: ");
String schedule = scanner.nextLine();
Course course = new Course(courseCode, title, description, capacity, schedule);
courseDatabase.addCourse(course);
System.out.println("Course added successfully.");
}
private void addStudent() {
System.out.print("Student ID: ");
String studentID = scanner.nextLine();
System.out.print("Name: ");
String name = scanner.nextLine();
Student student = new Student(studentID, name);
studentDatabase.addStudent(student);
System.out.println("Student added successfully.");
}
private void registerCourse() {
System.out.print("Student ID: ");
String studentID = scanner.nextLine();
System.out.print("Course Code: ");
String courseCode = scanner.nextLine();
Student student = studentDatabase.findStudentByID(studentID);
Course course = courseDatabase.findCourseByCode(courseCode);
if (student != null && course != null) {
if (student.registerCourse(course)) {
System.out.println("Course registered successfully.");
} else {
System.out.println("Failed to register course. It may be full or already registered.");
}
} else {
System.out.println("Invalid student ID or course code.");
}
}
private void dropCourse() {
System.out.print("Student ID: ");
String studentID = scanner.nextLine();
System.out.print("Course Code: ");
String courseCode = scanner.nextLine();
Student student = studentDatabase.findStudentByID(studentID);
Course course = courseDatabase.findCourseByCode(courseCode);
if (student != null && course != null) {
if (student.dropCourse(course)) {
System.out.println("Course dropped successfully.");
} else {
System.out.println("Failed to drop course. It may not be registered.");
}
} else {
System.out.println("Invalid student ID or course code.");
}
}
public static void main(String[] args) {
CourseRegistrationSystem system = new CourseRegistrationSystem();
system.run();
}
}