forked from ArefeRoosta/WS-02-intro-to-oop
complete all TODO sections
This commit is contained in:
@@ -1,14 +1,75 @@
|
||||
package CourseRegistrationStarter;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
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 course1 = new Course("َAP", "1414", 2);
|
||||
Course course2 = new Course("DS", "2201", 1);
|
||||
Course course3 = new Course("DB", "3301", 3);
|
||||
Student student1 = new Student("Ali", "402222001");
|
||||
RegistrationSystem registrationSystem = new RegistrationSystem();
|
||||
registrationSystem.addCourseToSystem(course1);
|
||||
registrationSystem.addCourseToSystem(course2);
|
||||
registrationSystem.addCourseToSystem(course3);
|
||||
|
||||
boolean isChosen = false;
|
||||
while (!isChosen)
|
||||
{
|
||||
System.out.println("\n--- Menu ---");
|
||||
System.out.println("1) Add course");
|
||||
System.out.println("2) Drop course");
|
||||
System.out.println("3) Show registered courses");
|
||||
System.out.println("4) Show all courses");
|
||||
System.out.println("5) Exit");
|
||||
System.out.print("Enter your choice: ");
|
||||
Scanner in = new Scanner(System.in);
|
||||
int chosen = in.nextInt();
|
||||
if (chosen == 1)
|
||||
{
|
||||
System.out.print("Enter Course Code to add: ");
|
||||
String codeToAdd = in.next();
|
||||
Course courseToAdd = registrationSystem.findCourseByCode(codeToAdd);
|
||||
|
||||
if (courseToAdd != null)
|
||||
{
|
||||
student1.addCourse(courseToAdd);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Error: Course not found in system.");
|
||||
}
|
||||
}
|
||||
else if (chosen == 2)
|
||||
{
|
||||
System.out.println("\n--- Drop Course ---");
|
||||
System.out.print("Enter Course Code to drop: ");
|
||||
String codeToDrop = in.next();
|
||||
Course courseToDrop = registrationSystem.findCourseByCode(codeToDrop);
|
||||
|
||||
if (courseToDrop != null)
|
||||
{
|
||||
student1.dropCourse(courseToDrop);
|
||||
}
|
||||
}
|
||||
else if (chosen == 3)
|
||||
{
|
||||
System.out.println("\n--- Registered Courses ---");
|
||||
student1.showRegisteredCourses();
|
||||
}
|
||||
else if (chosen == 4)
|
||||
{
|
||||
System.out.println("\n--- All Available Courses ---");
|
||||
registrationSystem.showAllCourses();
|
||||
}
|
||||
else if (chosen == 5)
|
||||
{
|
||||
isChosen = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Invalid! Please enter a number between 1 and 5.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user