implement tasks based on README
This commit is contained in:
@@ -3,6 +3,20 @@ package CourseRegistrationStarter;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO:
|
||||
Course BP = new Course("Basic Programming", "BP1404", 3);
|
||||
Course AP = new Course("Advanced Programming", "AP1405", 2);
|
||||
Course DS = new Course("Data Structure", "DS1406", 2);
|
||||
Student saeedJam = new Student("Saeed Jamali", "404222000");
|
||||
RegistrationSystem register = new RegistrationSystem();
|
||||
|
||||
register.addCourseToSystem(BP);
|
||||
register.addCourseToSystem(AP);
|
||||
register.addCourseToSystem(DS);
|
||||
|
||||
saeedJam.addCourse(AP);
|
||||
saeedJam.addCourse(DS);
|
||||
saeedJam.dropCourse(DS);
|
||||
saeedJam.showRegisteredCourses();
|
||||
// 1. Create at least 3 courses
|
||||
// 2. Create 1 student
|
||||
// 3. Create a registration system
|
||||
|
||||
@@ -9,16 +9,25 @@ public class RegistrationSystem {
|
||||
}
|
||||
|
||||
public void addCourseToSystem(Course c) {
|
||||
this.courses.add(c);
|
||||
// TODO: Add the course to the system
|
||||
}
|
||||
|
||||
public Course findCourseByCode(String code) {
|
||||
for (Course c: this.courses) {
|
||||
if (c.getCourseCode().equals(code)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
// TODO: Search for a course by course code
|
||||
// Return the matching course if found, otherwise return null
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showAllCourses() {
|
||||
for(Course c: this.courses) {
|
||||
System.out.println(c.getCourseName() + ", code: " + c.getCourseCode());
|
||||
}
|
||||
// TODO: Print all courses in the system
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,22 @@ public class Student {
|
||||
}
|
||||
|
||||
public boolean addCourse(Course c) {
|
||||
if (c.getCapacity() > 0 && !this.registeredCourses.contains(c)) {
|
||||
this.registeredCourses.add(c);
|
||||
c.reduceCapacity();
|
||||
return true;
|
||||
}
|
||||
// TODO: Register the student in the course if capacity allows
|
||||
// Return true if registration was successful, otherwise false
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean dropCourse(Course c) {
|
||||
if (this.registeredCourses.contains(c)) {
|
||||
this.registeredCourses.remove(c);
|
||||
c.increaseCapacity();
|
||||
return true;
|
||||
}
|
||||
// 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
|
||||
@@ -34,6 +44,9 @@ public class Student {
|
||||
}
|
||||
|
||||
public void showRegisteredCourses() {
|
||||
for(Course c: this.registeredCourses) {
|
||||
System.out.println(c.getCourseName() + ", code: " + c.getCourseCode());
|
||||
}
|
||||
// TODO: Print all registered courses
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user