0% found this document useful (0 votes)
2 views

StudentInformationSystem (1)

The document outlines the design and implementation of a Student Information System, which includes managing student records, courses, and grades through various object-oriented programming concepts such as classes, encapsulation, inheritance, and polymorphism. Key features include adding and managing student records, creating courses, enrolling students, and calculating grades. The provided source code includes classes for Student, GraduateStudent, Course, and Enrollment, along with methods for user interaction and data management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

StudentInformationSystem (1)

The document outlines the design and implementation of a Student Information System, which includes managing student records, courses, and grades through various object-oriented programming concepts such as classes, encapsulation, inheritance, and polymorphism. Key features include adding and managing student records, creating courses, enrolling students, and calculating grades. The provided source code includes classes for Student, GraduateStudent, Course, and Enrollment, along with methods for user interaction and data management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

BSIT – 2D

Members:

Cabinta, Thristan Kurt

Deduque, Mark Jude

Figuracion, Aldwane

Gabriel, Vince Michael

Oliveros, Greg Angelo

Student Information System

Objective: Build a system to manage student records, courses, and grades.

Requirements:

• Classes and Objects: Implement classes for Student, Course, and Enrollment.

• Encapsulation: Use private fields with getter and setter methods.

• Inheritance: Create a subclass GraduateStudent extending Student.

• Polymorphism: Override methods to provide specific implementations for

GraduateStudent.

• Interfaces: Implement an interface Grading with methods like calculateGrade().

• Collections: Use collections to manage students, courses, and enrollments.

Features:

• Add and manage student records.

• Create and assign courses.

• Enroll students in courses and calculate grades.


Source Code:

import java.util.*;

// Interface for grading


interface Grading {
String calculateGrade(int midtermGrade, int finalGrade);
}

// Base Student class


class Student {
private String studentId;
private String name;
private String email;

public Student(String name, String studentId, String email) {


this.name = name;
this.studentId = studentId;
this.email = email;
}

public String getName() {


return name;
}

public String getStudentId() {


return studentId;
}

public String getEmail() {


return email;
}

public void displayDetails() {


System.out.println("Name: " + name);
System.out.println("Student ID: " + studentId);
System.out.println("Email: " + email);
}

public boolean isGraduated() {


return false; // By default, regular students are not graduated
}
}

// GraduateStudent subclass with batch year


class GraduateStudent extends Student {
private String batchYear;

public GraduateStudent(String studentId, String name, String email, String batchYear) {


super(name, studentId, email);
this.batchYear = batchYear;
}

@Override
public void displayDetails() {
super.displayDetails();
System.out.println("Batch Year: " + batchYear);
}

@Override
public boolean isGraduated() {
return true; // Graduate students are considered graduated
}
}

// Course class
class Course {
private String courseId;
private String courseName;
private int credits;

public Course(String courseId, String courseName, int credits) {


this.courseId = courseId;
this.courseName = courseName;
this.credits = credits;
}

public String getCourseId() {


return courseId;
}

public void displayDetails() {


System.out.println("Course ID: " + courseId);
System.out.println("Course Name: " + courseName);
System.out.println("Credits: " + credits);
}
}

// Enrollment class implementing Grading


class Enrollment implements Grading {
private String studentId;
private String courseId;
private int midtermGrade;
private int endtermGrade;
private double finalGrade;

public String getStudentId() {


return studentId;
}

public String getCourseId() {


return courseId;
}

public Enrollment(String studentId, String courseId) {


this.studentId = studentId;
this.courseId = courseId;
}

public void setGrades(int midtermGrade, int endtermGrade) {


this.midtermGrade = midtermGrade;
this.endtermGrade = endtermGrade;
this.finalGrade = (midtermGrade + endtermGrade) / 2.0;
}

@Override
public String calculateGrade(int midtermGrade, int endtermGrade) {
setGrades(midtermGrade, endtermGrade);
return String.format("%.2f", finalGrade);
}

public void displayDetails() {


System.out.println("Student ID: " + studentId);
System.out.println("Course ID: " + courseId);
System.out.println("Midterm Grade: " + midtermGrade);
System.out.println("Endterm Grade: " + endtermGrade);
System.out.println("Final Grade: " + finalGrade);
}
}

// Main Class
public class StudentInformationSystem {
private static List<Student> students = new ArrayList<>();
private static List<Course> courses = new ArrayList<>();
private static List<Enrollment> enrollments = new ArrayList<>();
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
System.out.println("\n--- Student Information System ---");
System.out.println("1. Add Student");
System.out.println("2. Add Course");
System.out.println("3. Enroll Student");
System.out.println("4. Display Students");
System.out.println("5. Display Courses");
System.out.println("6. Display Enrollments");
System.out.println("7. Calculate Grade");
System.out.println("8. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline

switch (choice) {
case 1 : addStudent();
break;
case 2 : addCourse();
break;
case 3 : enrollStudent();
break;
case 4 : displayStudents();
break;
case 5 : displayCourses();
break;
case 6 : displayEnrollments();
break;
case 7 : calculateGrade();
break;
case 8 : {
System.out.println("Exiting...");
return;
}
default : System.out.println("Invalid choice! Try again.");
}
}
}
//Method to add Students
private static void addStudent() {
System.out.print("Enter Student ID: ");
String studentId = scanner.next();

// Check if the student ID already exists


for (Student student : students) {
if (student.getStudentId().equals(studentId)) {
System.out.println("Error: Student ID already exists! Please enter a unique ID.");
return;
}
}

System.out.print("Enter Name: ");


String name = scanner.next();
System.out.print("Enter Email: ");
String email = scanner.next();
System.out.print("Is this a graduate student? (yes/no): ");
String isGraduate = scanner.next();

if (isGraduate.equalsIgnoreCase("yes")) {
System.out.print("Enter Batch Year: ");
String batchYear = scanner.next();
students.add(new GraduateStudent(studentId, name, email, batchYear));
} else {
students.add(new Student(name, studentId, email));
}
System.out.println(name + " has been added successfully!");
}
//Method to add course
private static void addCourse() {
System.out.print("Enter Course ID: ");
String courseId = scanner.next();

// Check if the course ID already exists


for (Course course : courses) {
if (course.getCourseId().equals(courseId)) {
System.out.println("Error: Course ID already exists! Please enter a unique ID.");
return;
}
}

System.out.print("Enter Course Name: ");


String courseName = scanner.next();
System.out.print("Enter Credits: ");
int credits = scanner.nextInt();
scanner.nextLine(); // Consume newline

courses.add(new Course(courseId, courseName, credits));


System.out.println(courseName + " has been added successfully!");
}
//Method to enroll student
private static void enrollStudent() {
if (students.isEmpty()) {
System.out.println("No students available. Please add students first.");
return;
}

if (courses.isEmpty()) {
System.out.println("No courses available. Please add courses first.");
return;
}

System.out.print("Enter Student ID: ");


String studentId = scanner.next();

Student selectedStudent = null;


for (Student student : students) {
if (student.getStudentId().equals(studentId)) {
selectedStudent = student;
break;
}
}

if (selectedStudent == null) {
System.out.println("Student not found!");
return;
}

if (selectedStudent.isGraduated()) {
System.out.println("This student is already graduated and cannot enroll.");
return;
}

System.out.print("Enter Course ID: ");


String courseId = scanner.next();

boolean courseExists = false;


for (Course course : courses) {
if (course.getCourseId().equals(courseId)) {
courseExists = true;
break;
}
}

if (!courseExists) {
System.out.println("Course not found!");
return;
}

enrollments.add(new Enrollment(studentId, courseId));


System.out.println("Student " + studentId + " has been enrolled successfully!");
}
//Method to display Students
private static void displayStudents() {
if (students.isEmpty()) {
System.out.println("No students available.");
} else {
for (Student student : students) {
student.displayDetails();
System.out.println();
}
}
}
//Method to display courses
private static void displayCourses() {
if (courses.isEmpty()) {
System.out.println("No courses available.");
} else {
for (Course course : courses) {
course.displayDetails();
System.out.println();
}
}
}
//Method to display Enrollments
private static void displayEnrollments() {
if (enrollments.isEmpty()) {
System.out.println("No enrollments available.");
} else {
for (Enrollment enrollment : enrollments) {
enrollment.displayDetails();
System.out.println();
}
}
}
//Method to calculate Grade
private static void calculateGrade() {
System.out.print("Enter Student ID: ");
String studentId = scanner.next();
System.out.print("Enter Course ID: ");
String courseId = scanner.next();
System.out.print("Enter Midterm Grade: ");
int midtermGrade = scanner.nextInt();
System.out.print("Enter Endterm Grade: ");
int finalGrade = scanner.nextInt();
scanner.nextLine(); // Consume newline

for (Enrollment enrollment : enrollments) {


if (enrollment.getStudentId().equals(studentId) &&
enrollment.getCourseId().equals(courseId)) {
enrollment.setGrades(midtermGrade, finalGrade);
System.out.println("Grades have been calculated and updated.");
return;
}
}
System.out.println("Enrollment not found for the given Student ID and Course ID.");
}
}

You might also like