Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fee2e981a | ||
|
|
5130cf9069 | ||
|
|
8ba322588e | ||
|
|
9731d3d3d7 |
@@ -151,7 +151,7 @@ public class Main {
|
||||
enrollInCourse(student);
|
||||
break;
|
||||
case 3:
|
||||
//System.out.print(student.getMyCoursesDisplay());
|
||||
System.out.print(student.getMyCoursesDisplay());
|
||||
break;
|
||||
case 4:
|
||||
System.out.println(" Goodbye, " + student.getUsername() + "!");
|
||||
@@ -166,12 +166,14 @@ public class Main {
|
||||
System.out.print(school.getAllCoursesDisplay());
|
||||
System.out.print("\nEnter Course ID to enroll: ");
|
||||
int courseId = getIntInput();
|
||||
|
||||
Course course = school.findCourseById(courseId);
|
||||
if (course == null) {
|
||||
System.out.println(" Course not found! Please enter a valid ID.");
|
||||
return;
|
||||
}
|
||||
if(student.enrolledCourses(course)){
|
||||
|
||||
if (student.enrollInCourse(course)) {
|
||||
System.out.println(" Successfully enrolled in " + course.getName());
|
||||
} else {
|
||||
System.out.println(" You are already enrolled in this course!");
|
||||
|
||||
@@ -11,7 +11,7 @@ public class Student extends User {
|
||||
this.enrolledCourses = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean enrolledCourses(Course course){
|
||||
public boolean enrollInCourse(Course course) {
|
||||
if (enrolledCourses.contains(course)) {
|
||||
return false;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class Student extends User {
|
||||
if (enrolledCourses.isEmpty()) {
|
||||
return " You are not enrolled in any course yet.";
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder("\n My Course: \n");
|
||||
StringBuilder sb = new StringBuilder("\n My Courses:\n");
|
||||
for (int i = 0; i < enrolledCourses.size(); i++) {
|
||||
sb.append(" ").append(i+1).append(". ").append(enrolledCourses.get(i)).append("\n");
|
||||
}
|
||||
|
||||
@@ -76,9 +76,7 @@ public class SchoolSystem {
|
||||
|
||||
public Course findCourseById(int id) {
|
||||
for (Course c : allCourses) {
|
||||
if (c.getId() == id){
|
||||
return c;
|
||||
}
|
||||
if (c.getId() == id) return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user