matin mortazavi / i did my Assignment + bonus
This commit is contained in:
@@ -23,17 +23,46 @@ public class Student {
|
||||
public boolean addCourse(Course c) {
|
||||
// TODO: Register the student in the course if capacity allows
|
||||
// Return true if registration was successful, otherwise false
|
||||
return false;
|
||||
if (registeredCourses.size()<= 10) {
|
||||
if (c.reduceCapacity()) {
|
||||
registeredCourses.add(c);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
return false;
|
||||
int ind = registeredCourses.indexOf(c) ;
|
||||
if (ind != -1 )
|
||||
{
|
||||
registeredCourses.remove(ind) ;
|
||||
c.increaseCapacity();
|
||||
return true ;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void showRegisteredCourses() {
|
||||
// TODO: Print all registered courses
|
||||
for (Course item : registeredCourses)
|
||||
{
|
||||
System.out.print("course name : ");
|
||||
System.out.print(item.getCourseName());
|
||||
System.out.print(" , course code");
|
||||
System.out.print(item.getCourseCode());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user