Compare commits
3
Commits
8ddd529c85
...
ea649bf1fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea649bf1fa | ||
|
|
b6c2286570 | ||
|
|
747406a5aa |
Generated
+1
@@ -0,0 +1 @@
|
||||
Student.java
|
||||
@@ -1,9 +1,10 @@
|
||||
package ClassExamples;
|
||||
import CourseRegistrationStarter.Course;
|
||||
|
||||
public class Example01
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println("Hi!");
|
||||
Course Advanced_Programming = new Course("AdvancedProgramming", "AP1404", 2);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,28 @@ 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 AdvancedProgramming = new Course("Advanced Programming", "AP1404", 2);
|
||||
Course DataStructures = new Course("Data Structures", "DS2201", 1);
|
||||
Course DatabaseSystems = new Course("Database Systems", "DB3301", 3);
|
||||
|
||||
Student Zahra = new Student("Zahra", "404222093");
|
||||
|
||||
RegistrationSystem TestSystem = new RegistrationSystem();
|
||||
|
||||
TestSystem.addCourseToSystem(AdvancedProgramming);
|
||||
TestSystem.addCourseToSystem(DataStructures);
|
||||
TestSystem.addCourseToSystem(DatabaseSystems);
|
||||
|
||||
System.out.print("Adding Advanced Programming: ");
|
||||
System.out.println(Zahra.addCourse(AdvancedProgramming));
|
||||
System.out.print("Adding Data Structures: ");
|
||||
System.out.println(Zahra.addCourse(DataStructures));
|
||||
System.out.print("Adding Database Systems: ");
|
||||
System.out.println(Zahra.addCourse(DatabaseSystems));
|
||||
|
||||
System.out.print("Dropping Data Structures: ");
|
||||
System.out.println(Zahra.dropCourse(DataStructures));
|
||||
|
||||
Zahra.showRegisteredCourses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package CourseRegistrationStarter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class RegistrationSystem {
|
||||
private ArrayList<Course> courses;
|
||||
@@ -9,16 +10,37 @@ 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 i : courses)
|
||||
{
|
||||
if (i.getCourseCode().equals(code))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Course findCourseByName(String name) {
|
||||
for (Course i : courses)
|
||||
{
|
||||
if (i.getCourseCode().equals(name))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showAllCourses() {
|
||||
// TODO: Print all courses in the system
|
||||
for (Course i : courses)
|
||||
{
|
||||
System.out.println(i.getCourseName());
|
||||
System.out.println(i.getCourseCode());
|
||||
System.out.println(i.getCapacity());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,19 +21,32 @@ 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
|
||||
return false;
|
||||
if ((registeredCourses.size() < 3) && (!(registeredCourses.contains(c)) && (c.getCapacity() > 0))) {
|
||||
registeredCourses.add(c);
|
||||
} else if (registeredCourses.size() >= 3)
|
||||
System.out.println("You can only attend 3 courses!");
|
||||
else if (registeredCourses.contains(c))
|
||||
System.out.println("You can't register twice!");
|
||||
return c.reduceCapacity();
|
||||
}
|
||||
|
||||
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.contains(c)) {
|
||||
registeredCourses.remove(c);
|
||||
c.increaseCapacity();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showRegisteredCourses() {
|
||||
// TODO: Print all registered courses
|
||||
System.out.println("_________________________________");
|
||||
System.out.println("You participate in:");
|
||||
for (Course i : registeredCourses) {
|
||||
System.out.println("=======================");
|
||||
System.out.println(i.getCourseName());
|
||||
System.out.print("Class ID: ");
|
||||
System.out.println(i.getCourseCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user