Compeleted the Student class (and Bonus).
This commit is contained in:
@@ -10,14 +10,7 @@ public class RegistrationSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addCourseToSystem(Course c) {
|
public void addCourseToSystem(Course c) {
|
||||||
Scanner scanner = new Scanner(System.in);
|
courses.add(c);
|
||||||
|
|
||||||
String courseName = scanner.next();
|
|
||||||
String courseCode = scanner.next();
|
|
||||||
int capacity = scanner.nextInt();
|
|
||||||
|
|
||||||
Course newCourse = new Course(courseName, courseCode, capacity);
|
|
||||||
courses.add(newCourse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Course findCourseByCode(String code) {
|
public Course findCourseByCode(String code) {
|
||||||
|
|||||||
@@ -21,18 +21,30 @@ public class Student {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean addCourse(Course c) {
|
public boolean addCourse(Course c) {
|
||||||
|
if ((registeredCourses.size() < 3)&&(!(registeredCourses.contains(c))&&(c.getCapacity() > 0))) {
|
||||||
return false;
|
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) {
|
public boolean dropCourse(Course c) {
|
||||||
// TODO: Remove the course from the student's list
|
registeredCourses.remove(c);
|
||||||
// Restore the course capacity if removal was successful
|
int temp = c.getCapacity();
|
||||||
// Return true if the course was dropped, otherwise false
|
c.increaseCapacity();
|
||||||
|
if ((temp > c.getCapacity())&&(!(registeredCourses.contains(c))))
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRegisteredCourses() {
|
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