Complete assignment #1
@@ -27,7 +27,7 @@ public class Main {
|
||||
student1.dropCourse(course2);
|
||||
|
||||
// 7. Print the final registered course list
|
||||
System.out.printf("%s registered courses:\n", student1.getName());
|
||||
System.out.printf("\n%s\'s registered courses:\n", student1.getName());
|
||||
student1.showRegisteredCourses();
|
||||
|
||||
System.out.println("\nRemaining informations of courses are as follows: ");
|
||||
|
||||
@@ -24,6 +24,15 @@ public class RegistrationSystem {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Course findCourseByName(String name){ // search by course name
|
||||
for(Course thisCourse : courses){
|
||||
if(thisCourse.getCourseName() == name){
|
||||
return thisCourse;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showAllCourses() {
|
||||
// TODO: Print all courses in the system
|
||||
System.out.println("Course Name | Course Code | Capacity");
|
||||
|
||||
@@ -5,6 +5,7 @@ public class Student {
|
||||
private String name;
|
||||
private String studentId;
|
||||
private ArrayList<Course> registeredCourses;
|
||||
private int allowedCourses = 2;
|
||||
|
||||
public Student(String name, String studentId) {
|
||||
this.name = name;
|
||||
@@ -24,11 +25,15 @@ public class Student {
|
||||
// TODO: Register the student in the course if capacity allows
|
||||
// Return true if registration was successful, otherwise false
|
||||
|
||||
if(registeredCourses.contains(c)){
|
||||
if(registeredCourses.contains(c)){ // Preventing duplicate course registration
|
||||
System.out.printf("%s is already registered for %s\n", c.getCourseName(), name);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(registeredCourses.size() >= allowedCourses){ // Limiting the number of courses per student
|
||||
System.out.printf("%s has reached his limit for registration.\n", name);
|
||||
}
|
||||
|
||||
if(c.reduceCapacity()){ // if enough capacity, reduction happens in this line
|
||||
registeredCourses.add(c);
|
||||
System.out.printf("%s registered successfully.\n", c.getCourseName());
|
||||
|
||||
Reference in New Issue
Block a user