Programming Assignment Unit 5
Programming Assignment Unit 5
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Student {
private String name;
private int studentID;
private List<Course> enrolledCourses;
class Course {
private String courseCode;
private String courseName;
private int maxCapacity;
private static int totalEnrolledStudents = 0;
class CourseManagement {
private static List<Course> courses = new ArrayList<>();
private static List<Student> students = new ArrayList<>();
class AdministratorInterface {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Student student = null; // Declare student variable
while (true) {
System.out.println("1. Add a new course");
System.out.println("2. Enroll students");
System.out.println("3. Assign grades");
System.out.println("4. Calculate overall course grades");
System.out.println("0. Exit");
switch (choice) {
case 1:
// Logic to add a new course
System.out.println("Enter course code: ");
String courseCode = scanner.nextLine();
System.out.println("Enter course name: ");
String courseName = scanner.nextLine();
System.out.println("Enter maximum capacity: ");
int maxCapacity = scanner.nextInt();
CourseManagement.addCourse(courseCode, courseName, maxCapacity);
System.out.println("Course added successfully!");
break;
case 2:
// Logic to enroll students
System.out.println("Enter student name: ");
String studentName = scanner.nextLine();
System.out.println("Enter student ID: ");
int studentID = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
// Find the course with the entered code and enroll the student
Course enrollCourse = CourseManagement.findCourseByCode(enrollCourseCode);
if (enrollCourse != null) {
CourseManagement.enrollStudent(student, enrollCourse);
System.out.println("Enrollment successful!");
} else {
System.out.println("Invalid course code. Enrollment failed.");
}
break;
case 3:
// Logic to assign grades
// ... (unchanged)
break;
case 4:
// Logic to calculate overall course grades
// ... (unchanged)
break;
case 0:
System.out.println("Exiting the program. Goodbye!");
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a valid numeric choice.");
}
}
}
}