implement bonus features
This commit is contained in:
@@ -7,7 +7,7 @@ public class Main {
|
|||||||
Course DataStructures = new Course("DataStructures", "DS2201", 1);
|
Course DataStructures = new Course("DataStructures", "DS2201", 1);
|
||||||
Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3);
|
Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3);
|
||||||
|
|
||||||
Student fateme = new Student("fateme", "404222000");
|
Student fateme = new Student("fateme", "404222000", 10);
|
||||||
|
|
||||||
RegistrationSystem A = new RegistrationSystem();
|
RegistrationSystem A = new RegistrationSystem();
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ public class RegistrationSystem {
|
|||||||
|
|
||||||
for (int i=0 ; i < courses.size() ; i++) {
|
for (int i=0 ; i < courses.size() ; i++) {
|
||||||
|
|
||||||
if(courses.get(i).getCourseCode().equals(c.getCourseCode())) {
|
if(courses.get(i).getCourseCode().equals(c.getCourseCode()) ||
|
||||||
|
courses.get(i).getCourseName().equals(c.getCourseName())) {
|
||||||
|
|
||||||
|
System.out.println("Course name or code already exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +34,15 @@ public class RegistrationSystem {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Course findCourseByName(String name) {
|
||||||
|
|
||||||
|
for(int i=0 ; i<courses.size() ; i++) {
|
||||||
|
if(courses.get(i).getCourseName().equals(name))
|
||||||
|
return courses.get(i);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void showAllCourses() {
|
public void showAllCourses() {
|
||||||
for(int i=0 ; i < courses.size() ; i++) {
|
for(int i=0 ; i < courses.size() ; i++) {
|
||||||
System.out.print("Course");
|
System.out.print("Course");
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package CourseRegistrationStarter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Student {
|
public class Student {
|
||||||
private String name;
|
private final String name;
|
||||||
private String studentId;
|
private final String studentId;
|
||||||
private ArrayList<Course> registeredCourses;
|
private ArrayList<Course> registeredCourses;
|
||||||
|
private int courseLimit;
|
||||||
|
|
||||||
public Student(String name, String studentId) {
|
public Student(String name, String studentId, int courseLimit) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.studentId = studentId;
|
this.studentId = studentId;
|
||||||
this.registeredCourses = new ArrayList<>();
|
this.registeredCourses = new ArrayList<>();
|
||||||
|
this.courseLimit = courseLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -22,7 +24,7 @@ public class Student {
|
|||||||
|
|
||||||
public boolean addCourse(Course c) {
|
public boolean addCourse(Course c) {
|
||||||
|
|
||||||
if(c.getCapacity() > 0) {
|
if(c.getCapacity() > 0 && registeredCourses.size() < courseLimit) {
|
||||||
registeredCourses.add(c);
|
registeredCourses.add(c);
|
||||||
c.reduceCapacity();
|
c.reduceCapacity();
|
||||||
return true;
|
return true;
|
||||||
@@ -30,6 +32,11 @@ public class Student {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCourseLimit(int amount) {
|
||||||
|
if(amount>0)
|
||||||
|
courseLimit = amount;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean dropCourse(Course c) {
|
public boolean dropCourse(Course c) {
|
||||||
if (registeredCourses.remove(c)) {
|
if (registeredCourses.remove(c)) {
|
||||||
c.increaseCapacity();
|
c.increaseCapacity();
|
||||||
|
|||||||
Reference in New Issue
Block a user