changes in class Student

This commit is contained in:
2026-04-20 22:40:21 +03:30
parent 8ddd529c85
commit e8bafc4140
+39 -11
View File
@@ -1,12 +1,15 @@
package CourseRegistrationStarter;
import java.util.ArrayList;
public class Student {
public class Student
{
private String name;
private String studentId;
private ArrayList<Course> registeredCourses;
private int limit = 15;
public Student(String name, String studentId) {
public Student(String name, String studentId)
{
this.name = name;
this.studentId = studentId;
this.registeredCourses = new ArrayList<>();
@@ -20,20 +23,45 @@ public class Student {
return studentId;
}
public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false
public boolean addCourse(Course c)
{
if(registeredCourses.contains(c) || c.getCapacity() == 0)
{
return false;
}
else if(registeredCourses.size() <= limit && c.getCapacity() > 0)
{
c.reduceCapacity();
registeredCourses.add(c);
return true;
}
return false;
}
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
public boolean dropCourse(Course c)
{
if(registeredCourses.contains(c))
{
registeredCourses.remove(c);
c.increaseCapacity();
return true;
}
return false;
}
public void showRegisteredCourses() {
// TODO: Print all registered courses
public void showRegisteredCourses()
{
if(registeredCourses.size() > 0)
{
System.out.println("Registered Courses : ");
for(int i = 0; i < registeredCourses.size(); i++) {
Course c = registeredCourses.get(i);
System.out.println(c.getCourseName());
}
}
else
{
System.out.println("NO COURSES !");
}
}
}