Merge PR 'student registered corses in oop' (#1) from develop into main - Full Mark 100/100 - No Bonus
Full Mark 100/100 - No Bonus
This commit was merged in pull request #1.
This commit is contained in:
@@ -2,13 +2,25 @@ package CourseRegistrationStarter;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO:
|
||||
// 1. Create at least 3 courses
|
||||
// 2. Create 1 student
|
||||
// 3. Create a registration system
|
||||
// 4. Add courses to the system
|
||||
// 5. Register the student in some courses
|
||||
// 6. Drop one course
|
||||
// 7. Print the final registered course list
|
||||
Course ap = new Course("Advanced Programing" , "AP1404" , 2);
|
||||
Course ds = new Course("Data Structures" , "DS2201" , 1);
|
||||
Course db = new Course("Database Systems" , "DB3301" , 3);
|
||||
|
||||
Student ali = new Student("Ali" , "402222001");
|
||||
|
||||
RegistrationSystem system = new RegistrationSystem();
|
||||
|
||||
system.addCourseToSystem(ap);
|
||||
system.addCourseToSystem(ds);
|
||||
system.addCourseToSystem(db);
|
||||
|
||||
ali.addCourse(ap);
|
||||
ali.addCourse(ds);
|
||||
|
||||
ali.dropCourse(ds);
|
||||
|
||||
ali.showRegisteredCourses();
|
||||
|
||||
system.showAllCourses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,16 +9,22 @@ public class RegistrationSystem {
|
||||
}
|
||||
|
||||
public void addCourseToSystem(Course c) {
|
||||
// TODO: Add the course to the system
|
||||
courses.add(c);
|
||||
}
|
||||
|
||||
public Course findCourseByCode(String code) {
|
||||
// TODO: Search for a course by course code
|
||||
// Return the matching course if found, otherwise return null
|
||||
for(Course c : courses){
|
||||
if(c.getCourseCode().equals(code)){
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showAllCourses() {
|
||||
// TODO: Print all courses in the system
|
||||
System.out.println("corses on system : ");
|
||||
for(Course c : courses){
|
||||
System.out.println(c.getCourseName() + "/" + c.getCourseCode() + " capacity :" + c.getCapacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,37 @@ 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
|
||||
if(registeredCourses.contains(c)){
|
||||
System.out.println("Studend registered in this corse!");
|
||||
return false;
|
||||
}
|
||||
if(c.reduceCapacity()){
|
||||
registeredCourses.add(c);
|
||||
System.out.println("corse added:" + c.getCourseName());
|
||||
return true;
|
||||
}
|
||||
System.out.println("corse is full");
|
||||
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
|
||||
if(registeredCourses.remove(c)){
|
||||
c.increaseCapacity();
|
||||
System.out.println("corse dropped :" + c.getCourseName());
|
||||
return true;
|
||||
}
|
||||
System.out.println("studend is not registered in this corse!");
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showRegisteredCourses() {
|
||||
// TODO: Print all registered courses
|
||||
System.out.println("registered corses for " + name + ":");
|
||||
if(registeredCourses.isEmpty()){
|
||||
System.out.println("no corses registered");
|
||||
return;
|
||||
}
|
||||
for(Course c : registeredCourses){
|
||||
System.out.println("- " + c.getCourseName() + "/" + c.getCourseCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user