develop to main #1
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,11 +4,26 @@ 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
|
||||||
|
Course AdvancedProgramming = new Course("Advanced Programming","123",2);
|
||||||
|
Course DataStructures = new Course("Data Structures","456",3);
|
||||||
|
Course DatabaseSystems = new Course("Database Systems","789",2);
|
||||||
// 2. Create 1 student
|
// 2. Create 1 student
|
||||||
|
Student Hadi = new Student("Hadi","40033037");
|
||||||
// 3. Create a registration system
|
// 3. Create a registration system
|
||||||
|
RegistrationSystem CS = new RegistrationSystem();
|
||||||
// 4. Add courses to the system
|
// 4. Add courses to the system
|
||||||
|
CS.addCourseToSystem(AdvancedProgramming);
|
||||||
|
CS.addCourseToSystem(DataStructures);
|
||||||
|
CS.addCourseToSystem(DatabaseSystems);
|
||||||
// 5. Register the student in some courses
|
// 5. Register the student in some courses
|
||||||
|
Hadi.addCourse(DataStructures);
|
||||||
|
Hadi.addCourse(DatabaseSystems);
|
||||||
|
Hadi.addCourse(AdvancedProgramming);
|
||||||
// 6. Drop one course
|
// 6. Drop one course
|
||||||
|
Hadi.dropCourse(DataStructures);
|
||||||
// 7. Print the final registered course list
|
// 7. Print the final registered course list
|
||||||
|
Hadi.showRegisteredCourses();
|
||||||
|
CS.showAllCourses();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,34 @@ public class RegistrationSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addCourseToSystem(Course c) {
|
public void addCourseToSystem(Course c) {
|
||||||
// TODO: Add the course to the system
|
if (courses.contains(c)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
courses.add(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Course findCourseByCode(String code) {
|
public Course findCourseByCode(String code) {
|
||||||
// TODO: Search for a course by course code
|
for (Course c : courses) {
|
||||||
// Return the matching course if found, otherwise return null
|
if (c.getCourseCode().equals(code)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showAllCourses() {
|
public void showAllCourses() {
|
||||||
// TODO: Print all courses in the system
|
for (Course c : courses) {
|
||||||
|
System.out.println(c.getCourseName()+" "+c.getCourseCode()+" "+c.getCapacity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Course findCourseByName(String name) {
|
||||||
|
for (Course c : courses) {
|
||||||
|
if (c.getCourseName().equals(name)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,19 +21,28 @@ public class Student {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean addCourse(Course c) {
|
public boolean addCourse(Course c) {
|
||||||
// TODO: Register the student in the course if capacity allows
|
if (registeredCourses.size() <= 3) {
|
||||||
// Return true if registration was successful, otherwise false
|
if (c.getCapacity() > 0) {
|
||||||
|
registeredCourses.add(c);
|
||||||
|
c.reduceCapacity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dropCourse(Course c) {
|
public boolean dropCourse(Course c) {
|
||||||
// TODO: Remove the course from the student's list
|
if (registeredCourses.contains(c)) {
|
||||||
// Restore the course capacity if removal was successful
|
registeredCourses.remove(c);
|
||||||
// Return true if the course was dropped, otherwise false
|
c.increaseCapacity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRegisteredCourses() {
|
public void showRegisteredCourses() {
|
||||||
// TODO: Print all registered courses
|
for (Course c : registeredCourses) {
|
||||||
|
System.out.println(c.getCourseName()+" "+c.getCourseCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user