Compare commits
1
Commits
41b8d9af0a
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66e86acde1 |
@@ -7,7 +7,7 @@ public class Main {
|
||||
Course DataStructures = new Course("DataStructures", "DS2201", 1);
|
||||
Course DatabaseSystems = new Course("DatabaseSystems", "DB3301", 3);
|
||||
|
||||
Student fateme = new Student("fateme", "404222000");
|
||||
Student fateme = new Student("fateme", "404222000", 10);
|
||||
|
||||
RegistrationSystem A = new RegistrationSystem();
|
||||
|
||||
|
||||
@@ -12,7 +12,10 @@ public class RegistrationSystem {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +34,15 @@ public class RegistrationSystem {
|
||||
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() {
|
||||
for(int i=0 ; i < courses.size() ; i++) {
|
||||
System.out.print("Course");
|
||||
|
||||
@@ -2,14 +2,16 @@ package CourseRegistrationStarter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Student {
|
||||
private String name;
|
||||
private String studentId;
|
||||
private final String name;
|
||||
private final String studentId;
|
||||
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.studentId = studentId;
|
||||
this.registeredCourses = new ArrayList<>();
|
||||
this.courseLimit = courseLimit;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -22,7 +24,7 @@ public class Student {
|
||||
|
||||
public boolean addCourse(Course c) {
|
||||
|
||||
if(c.getCapacity() > 0) {
|
||||
if(c.getCapacity() > 0 && registeredCourses.size() < courseLimit) {
|
||||
registeredCourses.add(c);
|
||||
c.reduceCapacity();
|
||||
return true;
|
||||
@@ -30,6 +32,11 @@ public class Student {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setCourseLimit(int amount) {
|
||||
if(amount>0)
|
||||
courseLimit = amount;
|
||||
}
|
||||
|
||||
public boolean dropCourse(Course c) {
|
||||
if (registeredCourses.remove(c)) {
|
||||
c.increaseCapacity();
|
||||
|
||||
Reference in New Issue
Block a user