0% found this document useful (0 votes)
38 views6 pages

Programming Assignment Unit 5

The document describes a student course enrollment and grade management system with classes for students, courses, and course management. It allows adding courses, enrolling students in courses, assigning grades, and calculating overall grades.

Uploaded by

albertmutoya57
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
38 views6 pages

Programming Assignment Unit 5

The document describes a student course enrollment and grade management system with classes for students, courses, and course management. It allows adding courses, enrolling students in courses, assigning grades, and calculating overall grades.

Uploaded by

albertmutoya57
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

ASSIGNMENT-5 COURSE ENROLLMENT AND GRADE MANAGEMENT SYSTEM

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Student {
private String name;
private int studentID;
private List<Course> enrolledCourses;

public Student(String name, int studentID) {


this.name = name;
this.studentID = studentID;
this.enrolledCourses = new ArrayList<>();
}

public String getName() {


return name;
}

public int getStudentID() {


return studentID;
}

public List<Course> getEnrolledCourses() {


return enrolledCourses;
}

public void enrollInCourse(Course course) {


enrolledCourses.add(course);
}

public void assignGrade(Course course, int grade) {


// Implement logic to assign grades
}
}

class Course {
private String courseCode;
private String courseName;
private int maxCapacity;
private static int totalEnrolledStudents = 0;

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


this.courseCode = courseCode;
this.courseName = courseName;
this.maxCapacity = maxCapacity;
}

public String getCourseCode() {


return courseCode;
}

public String getCourseName() {


return courseName;
}

public int getMaxCapacity() {


return maxCapacity;
}

public static int getTotalEnrolledStudents() {


return totalEnrolledStudents;
}

public static void incrementEnrolledStudents() {


totalEnrolledStudents++;
}
}

class CourseManagement {
private static List<Course> courses = new ArrayList<>();
private static List<Student> students = new ArrayList<>();

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


Course newCourse = new Course(courseCode, courseName, maxCapacity);
courses.add(newCourse);
}

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


if (course.getMaxCapacity() > Course.getTotalEnrolledStudents()) {
student.enrollInCourse(course);
Course.incrementEnrolledStudents();
} else {
System.out.println("Course has reached maximum capacity. Enrollment failed.");
}
}

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


student.assignGrade(course, grade);
}
public static void calculateOverallGrade(Student student) {
// Implement logic to calculate overall course grade for the student
}

public static List<Course> getCourses() {


return courses;
}

public static List<Student> getStudents() {


return students;
}

public static Student findStudentByID(int studentID) {


for (Student student : students) {
if (student.getStudentID() == studentID) {
return student;
}
}
return null;
}

public static Course findCourseByCode(String courseCode) {


for (Course course : courses) {
if (course.getCourseCode().equals(courseCode)) {
return course;
}
}
return null;
}
}

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");

System.out.print("Enter your choice: ");


try {
int choice = Integer.parseInt(scanner.nextLine());

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

// Initialize student here


student = new Student(studentName, studentID);

// Display available courses for enrollment


System.out.println("Available courses for enrollment:");
for (Course c : CourseManagement.getCourses()) {
System.out.println(c.getCourseCode() + ": " + c.getCourseName());
}

// Prompt for course code to enroll in


System.out.println("Enter course code to enroll in: ");
String enrollCourseCode = scanner.nextLine().trim();

// 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.");
}
}
}
}

You might also like