implement bonus features
This commit is contained in:
@@ -2,14 +2,16 @@ package CourseRegistrationStarter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Student {
|
||||
private String name;
|
||||
private String studentId;
|
||||
private final String name;
|
||||
private final String studentId;
|
||||
private ArrayList<Course> registeredCourses;
|
||||
private int courseLimit;
|
||||
|
||||
public Student(String name, String studentId) {
|
||||
public Student(String name, String studentId, int courseLimit) {
|
||||
this.name = name;
|
||||
this.studentId = studentId;
|
||||
this.registeredCourses = new ArrayList<>();
|
||||
this.courseLimit = courseLimit;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -22,7 +24,7 @@ public class Student {
|
||||
|
||||
public boolean addCourse(Course c) {
|
||||
|
||||
if(c.getCapacity() > 0) {
|
||||
if(c.getCapacity() > 0 && registeredCourses.size() < courseLimit) {
|
||||
registeredCourses.add(c);
|
||||
c.reduceCapacity();
|
||||
return true;
|
||||
@@ -30,6 +32,11 @@ public class Student {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setCourseLimit(int amount) {
|
||||
if(amount>0)
|
||||
courseLimit = amount;
|
||||
}
|
||||
|
||||
public boolean dropCourse(Course c) {
|
||||
if (registeredCourses.remove(c)) {
|
||||
c.increaseCapacity();
|
||||
|
||||
Reference in New Issue
Block a user