0% found this document useful (0 votes)
4 views19 pages

Programming Assignment Unit 5

The document outlines a Course Management System designed to manage courses, students, and grades in higher education. It includes a Java implementation with classes for Course and Student, methods for adding courses, enrolling students, assigning grades, and calculating overall grades. The system features an interactive command-line interface for administrators to perform various management tasks.

Uploaded by

nazilaramzi25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views19 pages

Programming Assignment Unit 5

The document outlines a Course Management System designed to manage courses, students, and grades in higher education. It includes a Java implementation with classes for Course and Student, methods for adding courses, enrolling students, assigning grades, and calculating overall grades. The system features an interactive command-line interface for administrators to perform various management tasks.

Uploaded by

nazilaramzi25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

The Importance of Effective Course Management in Higher Education

CS 1102-01 Programming 1 - AY2025-T5

Programming Assignment Unit 5

Instructor: Salah Jabareen

July 24, 2025


Program Code:
import java.util.*;

public class CourseManagement {


private static List<Course> courses = new ArrayList<>();
private static Map<Student, Map<Course, Double>> studentGrades = new HashMap<>();

// Course Class
public static class Course
{ private String courseCode;
private String courseName;
private int maxCapacity;
private List<Student> enrolledStudents;

// Static variable to track total enrolled students


private static int totalEnrolledStudents = 0;

public Course(String courseCode, String courseName, int maxCapacity)


{ this.courseCode = courseCode;
this.courseName = courseName;
this.maxCapacity = maxCapacity;
this.enrolledStudents = new ArrayList<>();
}

public String getCourseCode()


{ return courseCode;
}

public String getCourseName()


{ return courseName;
}

public int getMaxCapacity() {


return maxCapacity;
}

public List<Student> getEnrolledStudents()


{ return enrolledStudents;
}

public void addStudent(Student student) {


if (enrolledStudents.size() < maxCapacity) {
enrolledStudents.add(student);
totalEnrolledStudents++;
} else {
System.out.println("Course capacity reached. Cannot enroll more students.");
}
}

public static int getTotalEnrolledStudents()


{ return totalEnrolledStudents;
}
}

// Student Class
public static class Student
{ private String name;
private int id;
private List<Course> enrolledCourses;
private Map<Course, Double> grades;
public Student(String name, int id)
{ this.name = name;
this.id = id;
this.enrolledCourses = new ArrayList<>();
this.grades = new HashMap<>();
}

public String getName()


{ return name;
}

public void setName(String name)


{ this.name = name;
}

public int getId()


{ return id;
}

public void setId(int id)


{ this.id = id;
}

public void enrollCourse(Course course) {


enrolledCourses.add(course);
course.addStudent(this);
}

public void assignGrade(Course course, double grade) {


grades.put(course, grade);
}
}

// CourseManagement Methods
public static void addCourse(String courseCode, String courseName, int maxCapacity) {
Course course = new Course(courseCode, courseName, maxCapacity);
courses.add(course);
}

public static void enrollStudent(Student student, Course course) {


student.enrollCourse(course);
}

public static void assignGrade(Student student, Course course, double grade)


{ student.assignGrade(course, grade);
}

public static double calculateOverallGrade(Student student)


{ double totalGrade = 0;
Map<Course, Double> studentCourseGrades = studentGrades.get(student);
for (Double grade : studentCourseGrades.values()) {
totalGrade += grade;
}
return totalGrade / studentCourseGrades.size();
}

// Administrator Interface
public static void main(String[] args)
{ Scanner scanner = new
Scanner(System.in);
while (true) {
System.out.println("1. Add Course");
System.out.println("2. Enroll Student");
System.out.println("3. Assign Grade");
System.out.println("4. Calculate Overall Grade");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline

switch (choice)
{ case 1:
addCourse();
break;
case 2:
enrollStudent();
break;
case 3:
assignGrade();
break;
case 4:
calculateOverallGrade();
break;
case 5:
System.out.println("Exiting...");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
}
}

// Interactive Methods for Administrator Interface


public static void addCourse() {
Scanner scanner = new
Scanner(System.in);
System.out.print("Enter course code: ");
String courseCode = scanner.nextLine();
System.out.print("Enter course name: ");
String courseName = scanner.nextLine();
System.out.print("Enter max capacity: ");
int maxCapacity = scanner.nextInt();
addCourse(courseCode, courseName, maxCapacity);
System.out.println("Course added successfully.");
}

public static void enrollStudent() {


Scanner scanner = new Scanner(System.in);
// Assume students and courses are already created
// For simplicity, let's assume the user enters valid student ID and course code
System.out.print("Enter student ID: ");
int studentId = scanner.nextInt();
System.out.print("Enter course code to enroll:
"); String courseCode = scanner.next();

// Find the student and course objects based on input


// Then, enroll the student in the course
// For simplicity, we skip the search part and directly enroll the student
Student student = new Student("John Doe", studentId);
Course course = new Course(courseCode, "Sample Course", 30);
enrollStudent(student, course);
System.out.println("Student enrolled successfully.");
}

public static void assignGrade() {


Scanner scanner = new Scanner(System.in);
// Assume students and courses are already created
// For simplicity, let's assume the user enters valid student ID, course code, and grade
System.out.print("Enter student ID: ");
int studentId = scanner.nextInt();
System.out.print("Enter course code: ");
String courseCode = scanner.next();
System.out.print("Enter grade: ");
double grade = scanner.nextDouble();

// Find the student and course objects based on input


// Then, assign the grade to the student for the course
// For simplicity, we skip the search part and directly assign the grade
Student student = new Student("John Doe", studentId);
Course course = new Course(courseCode, "Sample Course", 30);
assignGrade(student, course, grade);
System.out.println("Grade assigned successfully.");
}

public static void calculateOverallGrade()


{ Scanner scanner = new Scanner(System.in);
// Assume students are already created
// For simplicity, let's assume the user enters valid student ID
System.out.print("Enter student ID: ");
int studentId = scanner.nextInt();

// Find the student object based on input


// Then, calculate the overall grade for the student
// For simplicity, we skip the search part and directly calculate the overall grade
Student student = new Student("John Doe", studentId);
double overallGrade = calculateOverallGrade(student);
System.out.println("Overall Grade: " + overallGrade);
}
}

Explanation of Code
import java.util.*;

- This line imports the `java.util` package and all its classes, including utilities for
handling collections, such as lists and maps, and input/output operations.

public class CourseManagement {

- This declares a public class named `CourseManagement`, which serves as the main
class for managing courses, students, and grades.

private static List<Course> courses = new ArrayList<>();


private static Map<Student, Map<Course, Double>> studentGrades = new HashMap<>();

- These lines declare static variables `courses` and `studentGrades` to store the list of
courses and the grades of students respectively. `courses` is a list of Course objects, while
`studentGrades` is a map where each student is mapped to a map of courses and their
corresponding grades.

public static class Course {


- This declares a nested static class `Course` inside the `CourseManagement` class to
represent courses.

private String courseCode;


private String
courseName; private int
maxCapacity;
private List<Student> enrolledStudents;
- These lines declare instance variables `courseCode`, `courseName`, `maxCapacity`, and
`enrolledStudents` to store information about a course. `courseCode` and
`courseName` store the code and name of the course, `maxCapacity` represents the maximum
number of students that can enroll in the course, and `enrolledStudents` is a list of students
enrolled in the course.

private static int totalEnrolledStudents = 0;

- This line declares a static variable `totalEnrolledStudents` to keep track of the total
number of students enrolled across all courses.

public Course(String courseCode, String courseName, int maxCapacity) {

- This line declares a constructor for the `Course` class with parameters to initialize the
course code, course name, and maximum capacity.

public String getCourseCode()


{ return courseCode;
}

- This line declares a getter method `getCourseCode()` to retrieve the course code.

public void addStudent(Student student) {

- This line declares a method `addStudent()` to add a student to the course.


public static int getTotalEnrolledStudents()
{ return totalEnrolledStudents;
}

- This line declares a static method `getTotalEnrolledStudents()` to retrieve the total


number of enrolled students across all courses.

public static class Student {

- This line declares a nested static class `Student` inside the `CourseManagement` class to
represent students.

private String name;


private int id;
private List<Course> enrolledCourses;
private Map<Course, Double> grades;

- These lines declare instance variables `name`, `id`, `enrolledCourses`, and `grades` to store
information about a student. `name` and `id` represent the name and ID of the student,
`enrolledCourses` is a list of courses the student is enrolled in, and `grades` is a map of
courses and their corresponding grades for the student.

public Student(String name, int id) {

- This line declares a constructor for the `Student` class with parameters to initialize the
student's name and ID.

public void enrollCourse(Course course) {

- This line declares a method `enrollCourse()` to enroll the student in a course.


public void assignGrade(Course course, double grade) {

- This line declares a method `assignGrade()` to assign a grade to the student for a
course.

public static void addCourse(String courseCode, String courseName, int maxCapacity) {

- This line declares a static method `addCourse()` to add a new course.

public static void enrollStudent(Student student, Course course) {

- This line declares a static method `enrollStudent()` to enroll a student in a course.

public static void assignGrade(Student student, Course course, double grade) {

- This line declares a static method `assignGrade()` to assign a grade to a student for a
course.

public static double calculateOverallGrade(Student student) {

- This line declares a static method `calculateOverallGrade()` to calculate the overall


grade for a student.

public static void main(String[] args) {

- This line declares the `main` method, which serves as the entry point of the program.

Scanner scanner = new Scanner(System.in);


- This line creates a new `Scanner` object to read input from the console.

while (true) {
- This line starts an infinite loop for the administrator interface.

System.out.println("1. Add Course");


System.out.println("2. Enroll Student");
System.out.println("3. Assign Grade");
System.out.println("4. Calculate Overall Grade");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
- These lines display the menu options for the administrator and prompt for user input.

switch (choice)
{ case 1:
addCourse();
break;
case 2:
enrollStudent();
break;
case 3:
assignGrade();
break;
case 4:
calculateOverallGrade();
break;
case 5:
System.out.println("Exiting...");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
- This block of code processes the user's choice and calls the corresponding methods
based on the selected option.

}
- This line ends the while loop for the administrator interface.

}
- This line marks the end of the `main` method.

}
- This line marks the end of the `CourseManagement` class.

SCREENSHOT FOR CODE:

Course Management System Documentation


Purpose:
The Course Management System is designed to facilitate the management of courses,
students, and grades within an educational institution. It allows administrators to add
courses, enroll students in courses, assign grades to students, and calculate overall grades for
students.
Usage:
The system provides an interactive command-line interface for administrators to perform
various tasks.
Classes:
CourseManagement:
- Purpose: Main class containing the administrator interface and interactive methods.
- Methods:
- `addCourse()`: Adds a new course to the system.
- `enrollStudent()`: Enrolls a student in a course.
- `assignGrade()`: Assigns a grade to a student for a specific course.
- `calculateOverallGrade()`: Calculates the overall grade for a student.
- `main(String[] args)`: Entry point for the program, displays the administrator interface
and handles user inputs.

Course:
- Purpose: Represents a course with course code, name, maximum capacity, and
enrolled students.
-Variables:
- `courseCode`: String representing the unique code of the course.
- `courseName`: String representing the name of the course.
- `maxCapacity`: Integer representing the maximum number of students that can enroll
in the course.
- `enrolledStudents`: List containing the students enrolled in the course.
- `totalEnrolledStudents`: Static variable tracking the total number of enrolled
students across all courses.
- Methods:
- `Course(String courseCode, String courseName, int maxCapacity)`: Constructor
to initialize course attributes.
- `getCourseCode()`, `getCourseName()`, `getMaxCapacity()`,
`getEnrolledStudents()`: Getter methods for accessing course attributes.
- `addStudent(Student student)`: Adds a student to the course if the maximum capacity
has not been reached.
- `getTotalEnrolledStudents()`: Static method to retrieve the total number of
enrolled students across all courses.

Student:
- Purpose: Represents a student with name, ID, enrolled courses, and grades.
-Variables:
- `name`: String representing the name of the student.
- `id`: Integer representing the unique ID of the student.
- `enrolledCourses`: List containing the courses in which the student is enrolled.
- `grades`: Map containing the grades assigned to the student for each course.
-Methods:
- `Student(String name, int id)`: Constructor to initialize student attributes.
- `getName()`, `setName()`, `getId()`, `setId()`: Getter and setter methods for accessing
and modifying student attributes.
- `enrollCourse(Course course)`: Enrolls the student in a course.
- `assignGrade(Course course, double grade)`: Assigns a grade to the student for a
specific course.
Static Methods and Variables:
-Purpose: Static methods and variables are used to track enrollment and grade-related
information across multiple instances of the Student and Course classes.
-Usage:
- `totalEnrolledStudents` in the Course class tracks the total number of enrolled students
across all courses. It is incremented whenever a student is successfully enrolled in a
course.
- Static methods such as `getTotalEnrolledStudents()` in the Course class provide a way
to retrieve the total number of enrolled students without needing to instantiate Course
objects.
Running the Program:
1. Compile: Compile the Java source file (`CourseManagement.java`) using a Java
compiler. javac CourseManagement.java
2. Run: Run the compiled bytecode file (`CourseManagement.class`) using the
Java interpreter.
java CourseManagement
3. Interaction: Follow the prompts displayed in the command-line interface to interact
with the administrator interface.
- Choose options to add courses, enroll students, assign grades, calculate overall grades, or
exit the program.
Example Usage:
1. Add a course:
1. Add Course
Enter course code: CS101
Enter course name: Introduction to Computer Science
Enter max capacity: 30
Course added successfully.
2. Enroll a student:
2. Enroll Student
Enter student ID: 123
Enter course code to enroll: CS101
Student enrolled successfully.
3. Assign a grade:
3. Assign Grade
Enter student ID:
123
Enter course code: CS101
Enter grade: 85.5
Grade assigned successfully.
4. Calculate overall grade:
4. Calculate Overall
Grade Enter student ID:
123 Overall Grade: 85.5
This documentation provides a comprehensive overview of the project, explaining its
purpose, usage, class structure, utilization of static methods and variables, and instructions
for running and interacting with the program.
References

Eck, D. J. (2022). Introduction to programming using java version 9, JavaFX

edition. Licensed under CC 4.0

Eck, D. J. (2019). Introduction to programming using Java, version 8.1. Hobart and William

Smith College. Retrieved, http://math.hws.edu/javanotes

You might also like