Student Registration System and Course Management System.
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Student {
private String name;
private int id;
private List<Course> enrolledCourses;
public Student(String name, int id) {
this.name = name;
this.id = id;
this.enrolledCourses = new ArrayList<>();
public void enrollCourse(Course course) {
enrolledCourses.add(course);
public void assignGrade(Course course, int grade) {
// update the student's grade for the course
}
public String getName() {
return name;
public int getId() {
return id;
public List<Course> getEnrolledCourses() {
return enrolledCourses;
class Course {
private String code;
private String name;
private int maximumCapacity;
private static int totalEnrolledStudents = 0;
public Course(String code, String name, int maximumCapacity) {
this.code = code;
this.name = name;
this.maximumCapacity = maximumCapacity;
totalEnrolledStudents++;
public static int getTotalEnrolledStudents() {
return totalEnrolledStudents;
public String getCode() {
return code;
public String getName() {
return name;
class CourseManagement {
private static List<Course> courses = new ArrayList<>();
private static Map<String, Double> overallGrades = new HashMap<>();
public static void addCourse(String code, String name, int maximumCapacity) {
Course course = new Course(code, name, maximumCapacity);
courses.add(course);
}
public static void enrollStudent(Student student, Course course) {
student.enrollCourse(course);
if (course.getMaximumCapacity() <= course.getTotalEnrolledStudents()) {
System.out.println("Course is full. Cannot enroll student.");
return;
course.totalEnrolledStudents++;
public static void assignGrade(Student student, Course course, int grade) {
student.assignGrade(course, grade);
overallGrades.put(student.getName(), overallGrades.getOrDefault(student.getName(), 0.0) +
grade);
public static double calculateOverallGrade(Student student) {
if (student.getEnrolledCourses().size() == 0) {
return 0.0;
return overallGrades.getOrDefault(student.getName(), 0.0) / student.getEnrolledCourses().size();
class AdministratorInterface {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Welcome to the Course Enrollment and Grade Management System!");
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("5. Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter course code: ");
String code = scanner.next();
System.out.print("Enter course name: ");
String name = scanner.next();
System.out.print("Enter maximum capacity: ");
int maximumCapacity = scanner.nextInt();
CourseManagement.addCourse(code, name, maximumCapacity);
break;
case 2:
System.out.print("Enter student ID: ");
int id = scanner.nextInt();
System.out.print("Enter student name: ");
String studentName = scanner.next();
Student student = new Student(studentName, id);
while (true) {
System.out.print("Enter course code to enroll (or 'q' to quit): ");
String enrollCode = scanner.next();
if (enrollCode.equalsIgnoreCase("q")) {
break;
for (Course course : CourseManagement.courses) {
if (course.getCode().equals(enrollCode)) {
CourseManagement.enrollStudent(student, course);
break;
break;
case 3:
System.out.print("Enter student ID: ");
id = scanner.nextInt();
System.out.print("Enter course code: ");
String enrollCode = scanner.next();
for (Course course : CourseManagement.courses) {
if (course.getCode().equals(enrollCode)) {
System.out.print("Enter grade: ");
int grade = scanner.nextInt();
CourseManagement.assignGrade(new Student(studentName, id), course, grade);
break;
break;
case 4:
System.out.print("Enter student ID: ");
id = scanner.nextInt();
double overallGrade = CourseManagement.calculateOverallGrade(new
Student(studentName, id));
if (overallGrade == 0.0) {
System.out.println("No courses enrolled yet.");
} else {
System.out.println("Overall grade: " + overallGrade);
break;
case 5:
System.exit(0);
}
}
Here's a brief code explanation:
Administrator Interface Class
This is the main class for the program, which provides an interface for administrators to manage courses
and students.
Menu Options
The program has 5 menu options:
1- Add a new course
2- Enroll students
3- Assign grades
4- Calculate overall course grades
5- Exit
Switch Statement
The program uses a switch statement to determine which option the user has chosen.
Case 1: Add a new course
Adds a new course to the system.
Case 2: Enroll students
Enrolls students in courses.
Case 3: Assign grades
Assigns grades to students for specific courses.
Case 4: Calculate overall course grades
Calculates the overall grade for a student based on their enrolled courses.
Case 5: Exit
Exits the program.
This code is used to manage courses and students in a educational system.