1 Commits
Author SHA1 Message Date
Mobina 42e098aea1 .. 2026-05-09 08:47:29 +03:30
3 changed files with 46 additions and 3 deletions
+19 -2
View File
@@ -1,6 +1,7 @@
package CourseRegistrationStarter; package CourseRegistrationStarter;
public class Main { public class Main
{
public static void main(String[] args) { public static void main(String[] args) {
// TODO: // TODO:
// 1. Create at least 3 courses // 1. Create at least 3 courses
@@ -10,5 +11,21 @@ public class Main {
// 5. Register the student in some courses // 5. Register the student in some courses
// 6. Drop one course // 6. Drop one course
// 7. Print the final registered course list // 7. Print the final registered course list
}
Course calculus = new Course("Calculus", "MATH101", 30);
Course combination = new Course("Combination", "MATH102", 25);
Course AP = new Course("AP Computer Science", "CS201", 20);
Student mobina = new Student("Mobina", "404222");
RegistrationSystem system = new RegistrationSystem();
system.addCourseToSystem(calculus);
system.addCourseToSystem(combination);
system.addCourseToSystem(AP);
mobina.addCourse(AP);
mobina.addCourse(calculus);
mobina.dropCourse(calculus);
mobina.showRegisteredCourses();
}
} }
@@ -10,15 +10,24 @@ public class RegistrationSystem {
public void addCourseToSystem(Course c) { public void addCourseToSystem(Course c) {
// TODO: Add the course to the system // TODO: Add the course to the system
courses.add(c);
} }
public Course findCourseByCode(String code) { public Course findCourseByCode(String code) {
// TODO: Search for a course by course code // TODO: Search for a course by course code
// Return the matching course if found, otherwise return null // Return the matching course if found, otherwise return null
for(int i=0; i<courses.size(); i++){
if (((courses.get(i)).getCourseCode()).equals(code))
return courses.get(i);
}
return null; return null;
} }
public void showAllCourses() { public void showAllCourses() {
// TODO: Print all courses in the system // TODO: Print all courses in the system
for (int i = 0; i < courses.size(); i++) {
System.out.println(courses.get(i).getCourseName());
}
} }
} }
@@ -23,6 +23,11 @@ public class Student {
public boolean addCourse(Course c) { public boolean addCourse(Course c) {
// TODO: Register the student in the course if capacity allows // TODO: Register the student in the course if capacity allows
// Return true if registration was successful, otherwise false // Return true if registration was successful, otherwise false
if (c.reduceCapacity())
registeredCourses.add(c);
return true;
else
return false; return false;
} }
@@ -30,10 +35,22 @@ public class Student {
// TODO: Remove the course from the student's list // TODO: Remove the course from the student's list
// Restore the course capacity if removal was successful // Restore the course capacity if removal was successful
// Return true if the course was dropped, otherwise false // Return true if the course was dropped, otherwise false
for(int i=0; i<registeredCourses.size(); i++){
if (c.getCourseName().equals(registeredCourses.get(i).getCourseName())){
registeredCourses.remove(i);
c.increaseCapacity();
return true;
}
}
return false; return false;
} }
public void showRegisteredCourses() { public void showRegisteredCourses() {
// TODO: Print all registered courses // TODO: Print all registered courses
for (int i=0; i<registeredCourses.size(); i++)
{
System.out.println(registeredCourses.get(i).getCourseName());
}
} }
} }