changes in class Student
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
package CourseRegistrationStarter;
|
package CourseRegistrationStarter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Student {
|
public class Student
|
||||||
|
{
|
||||||
private String name;
|
private String name;
|
||||||
private String studentId;
|
private String studentId;
|
||||||
private ArrayList<Course> registeredCourses;
|
private ArrayList<Course> registeredCourses;
|
||||||
|
private int limit = 15;
|
||||||
|
|
||||||
public Student(String name, String studentId) {
|
public Student(String name, String studentId)
|
||||||
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.studentId = studentId;
|
this.studentId = studentId;
|
||||||
this.registeredCourses = new ArrayList<>();
|
this.registeredCourses = new ArrayList<>();
|
||||||
@@ -20,20 +23,45 @@ public class Student {
|
|||||||
return studentId;
|
return studentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addCourse(Course c) {
|
public boolean addCourse(Course c)
|
||||||
// TODO: Register the student in the course if capacity allows
|
{
|
||||||
// Return true if registration was successful, otherwise false
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dropCourse(Course c) {
|
public boolean dropCourse(Course c)
|
||||||
// TODO: Remove the course from the student's list
|
{
|
||||||
// Restore the course capacity if removal was successful
|
if(registeredCourses.contains(c))
|
||||||
// Return true if the course was dropped, otherwise false
|
{
|
||||||
|
registeredCourses.remove(c);
|
||||||
|
c.increaseCapacity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRegisteredCourses() {
|
public void showRegisteredCourses()
|
||||||
// TODO: Print all registered courses
|
{
|
||||||
|
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 !");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user