Compeleted the Student class (and Bonus).
This commit is contained in:
@@ -10,14 +10,7 @@ public class RegistrationSystem {
|
||||
}
|
||||
|
||||
public void addCourseToSystem(Course c) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
String courseName = scanner.next();
|
||||
String courseCode = scanner.next();
|
||||
int capacity = scanner.nextInt();
|
||||
|
||||
Course newCourse = new Course(courseName, courseCode, capacity);
|
||||
courses.add(newCourse);
|
||||
courses.add(c);
|
||||
}
|
||||
|
||||
public Course findCourseByCode(String code) {
|
||||
|
||||
@@ -21,18 +21,30 @@ public class Student {
|
||||
}
|
||||
|
||||
public boolean addCourse(Course c) {
|
||||
|
||||
return false;
|
||||
if ((registeredCourses.size() < 3)&&(!(registeredCourses.contains(c))&&(c.getCapacity() > 0))) {
|
||||
registeredCourses.add(c);
|
||||
}
|
||||
else if (registeredCourses.size() >= 3)
|
||||
System.out.println("You can only attend 3 courses!");
|
||||
else if (registeredCourses.contains(c))
|
||||
System.out.println("You can't register twice!");
|
||||
return c.reduceCapacity();
|
||||
}
|
||||
|
||||
public boolean dropCourse(Course c) {
|
||||
// TODO: Remove the course from the student's list
|
||||
// Restore the course capacity if removal was successful
|
||||
// Return true if the course was dropped, otherwise false
|
||||
registeredCourses.remove(c);
|
||||
int temp = c.getCapacity();
|
||||
c.increaseCapacity();
|
||||
if ((temp > c.getCapacity())&&(!(registeredCourses.contains(c))))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showRegisteredCourses() {
|
||||
// TODO: Print all registered courses
|
||||
for (Course i : registeredCourses)
|
||||
{
|
||||
System.out.println(i.getCourseName());
|
||||
System.out.println(i.getCourseCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user