Browse Source

Adding addCourseFromUserInput method in Course class

remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
46b6240589
  1. 24
      src/main/java/org/example/Course.java

24
src/main/java/org/example/Course.java

@ -2,6 +2,7 @@ package org.example;
import java.io.*; import java.io.*;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
@ -161,4 +162,27 @@ public class Course {
} }
return false; // No course with the same name or code found return false; // No course with the same name or code found
} }
public static void addCourseFromUserInput(String filename) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the name of the course: ");
String courseName = scanner.nextLine();
System.out.print("Enter the code of the course: ");
String courseCode = scanner.nextLine();
// Check if the course already exists
if (courseExists(filename, courseName, courseCode)) {
System.out.println("Course with the same name or code already exists.");
return;
}
System.out.print("Enter the credit value of the course: ");
int courseCredit = scanner.nextInt();
// Add the course using the provided data
addCourse(courseName, courseCode, courseCredit, filename);
System.out.println("Added Course successfully!");
}
} }
Loading…
Cancel
Save