-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseDetail1.java
More file actions
60 lines (51 loc) · 1.94 KB
/
CourseDetail1.java
File metadata and controls
60 lines (51 loc) · 1.94 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
public class CourseDetail1 {
String courseName;
int enrollments;
static int maxCapacity = 10;
String[] enrolledStudents;
static void setMaxCapacity(int maxCapacity) {
CourseDetail1.maxCapacity = maxCapacity;
}
CourseDetail1(String courseName) {
this.courseName = courseName;
this.enrollments = 0;
this.enrolledStudents = new String[maxCapacity];
}
void enrollStudent(String studentName) {
if (enrollments < maxCapacity) {
enrolledStudents[enrollments] = studentName;
System.out.println("Congratulation, enrolled student: " + studentName);
enrollments++;
} else {
System.out.println("Enrollment failed. Course is at maximum capacity.");
}
}
void unenrollStudent(String studentName) {
boolean found = false;
for (int i = 0; i < enrollments; i++) {
if (enrolledStudents[i].equals(studentName)) {
found = true;
for (int j = i; j < enrollments - 1; j++) {
enrolledStudents[j] = enrolledStudents[j + 1];
}
enrolledStudents[enrollments - 1] = null;
enrollments--;
System.out.println("Student removed: " + studentName);
break;
}
}
if (!found) {
System.out.println("Student not found: " + studentName);
}
}
public static void main(String[] args) {
CourseDetail1 course = new CourseDetail1("Java Core");
course.enrollStudent("Aditya Kumar");
course.enrollStudent("Rishu Kumar");
course.enrollStudent("Rohit Kumar");
course.enrollStudent("Shushant Kumar");
course.enrollStudent("Mohit Kumar");
course.unenrollStudent("Mohit Kumar");
// Try enrolling a student when the course is full
}
}