Compeleted the Student class (and Bonus).

This commit is contained in:
2026-04-20 22:01:20 +03:30
parent 747406a5aa
commit b6c2286570
2 changed files with 19 additions and 14 deletions
@@ -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) {
+18 -6
View File
@@ -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());
}
}
}