This commit is contained in:
2025mohseni
2026-07-15 18:11:56 +03:30
parent 3cb0489679
commit 8332230000
4 changed files with 102 additions and 156 deletions
+48 -62
View File
@@ -4,72 +4,58 @@ import java.util.Scanner;
public class Main {
public static void main(String[] args) {
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);
Scanner scanner = new Scanner(System.in);
RegistrationSystem system = new RegistrationSystem();
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);
system.addCourseToSystem(new Course("Advanced Programming", "CS101", 30));
system.addCourseToSystem(new Course("Data Structures", "CS102", 25));
system.addCourseToSystem(new Course("Database Systems", "CS103", 20));
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.");
System.out.print("Enter Student Name: ");
String sName = scanner.nextLine();
System.out.print("Enter Student ID: ");
String sId = scanner.nextLine();
Student student = new Student(sName, sId);
boolean running = true;
while (running) {
System.out.println("\n1. View All Courses\n2. Add Course\n3. Drop Course\n4. My Courses\n5. Exit");
System.out.print("Choice: ");
String choice = scanner.nextLine();
switch (choice) {
case "1":
system.showAllCourses();
break;
case "2":
System.out.print("Enter course code to add: ");
String addCode = scanner.nextLine();
Course toAdd = system.findCourseByCode(addCode);
if (toAdd != null) {
if (student.addCourse(toAdd)) System.out.println("Successfully added.");
} else {
System.out.println("Course not found!");
}
break;
case "3":
System.out.print("Enter course code to drop: ");
String dropCode = scanner.nextLine();
if (student.dropCourse(dropCode)) System.out.println("Successfully dropped.");
else System.out.println("You are not registered in this course.");
break;
case "4":
student.showRegisteredCourses();
break;
case "5":
running = false;
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid option.");
}
}
scanner.close();
}
}