Complete all classes . #1
Generated
+1
@@ -0,0 +1 @@
|
||||
Course.java
|
||||
@@ -4,11 +4,36 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO:
|
||||
// 1. Create at least 3 courses
|
||||
|
||||
Course course1 = new Course("Advanced Programming" , "AP1404", 2) ;
|
||||
Course course2 = new Course("Data Structures", "DS2201", 1) ;
|
||||
Course course3 = new Course("Database Systems", "DB3301", 3) ;
|
||||
|
||||
// 2. Create 1 student
|
||||
|
||||
Student student1 = new Student ("Ali", "402222001") ;
|
||||
|
||||
// 3. Create a registration system
|
||||
|
||||
RegistrationSystem registrationSystem = new RegistrationSystem() ;
|
||||
|
||||
// 4. Add courses to the system
|
||||
|
||||
registrationSystem.addCourseToSystem(course1) ;
|
||||
registrationSystem.addCourseToSystem(course2) ;
|
||||
registrationSystem.addCourseToSystem(course3) ;
|
||||
|
||||
// 5. Register the student in some courses
|
||||
|
||||
student1.addCourse(course1) ;
|
||||
student1.addCourse(course2) ;
|
||||
student1.addCourse(course3) ;
|
||||
// 6. Drop one course
|
||||
|
||||
student1.dropCourse(course2) ;
|
||||
// 7. Print the final registered course list
|
||||
|
||||
student1.showRegisteredCourses() ;
|
||||
registrationSystem.showAllCourses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,27 @@ 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
|
||||
for (int i = 0 ; i < courses.size() ; i++)
|
||||
{
|
||||
if ( courses.get(i).getCourseCode().equals(code))
|
||||
{
|
||||
return courses.get(i);
|
||||
}
|
||||
}
|
||||
// Return the matching course if found, otherwise return null
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showAllCourses() {
|
||||
// TODO: Print all courses in the system
|
||||
for (int i = 0 ; i < courses.size() ; i++)
|
||||
{
|
||||
System.out.println(courses.get(i).getCourseName() + " (" + courses.get(i).getCourseCode() + ") - Remaining Capacity: " + courses.get(i).getCapacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,26 @@ public class Student {
|
||||
|
||||
public boolean addCourse(Course c) {
|
||||
// TODO: Register the student in the course if capacity allows
|
||||
|
||||
if (c.getCapacity() > 0)
|
||||
{
|
||||
registeredCourses.add(c) ;
|
||||
c.reduceCapacity() ;
|
||||
return true ;
|
||||
}
|
||||
// Return true if registration was successful, otherwise false
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean dropCourse(Course c) {
|
||||
// TODO: Remove the course from the student's list
|
||||
|
||||
if (registeredCourses.remove(c))
|
||||
{
|
||||
c.increaseCapacity() ;
|
||||
return true ;
|
||||
|
||||
}
|
||||
// Restore the course capacity if removal was successful
|
||||
// Return true if the course was dropped, otherwise false
|
||||
return false;
|
||||
@@ -35,5 +49,10 @@ public class Student {
|
||||
|
||||
public void showRegisteredCourses() {
|
||||
// TODO: Print all registered courses
|
||||
|
||||
for(int i = 0 ; i < registeredCourses.size() ; i++)
|
||||
{
|
||||
System.out.println(registeredCourses.get(i).getCourseName() + " - " + registeredCourses.get(i).getCourseCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user