Skip to content

Java-based database management system demonstrating OOP principles

License

Notifications You must be signed in to change notification settings

FidelAP-19/School-Database-System

Repository files navigation

School Database Management System

A comprehensive Java-based database management system for educational institutions, demonstrating object-oriented programming principles through multi-level inheritance, file I/O operations, and a full-featured menu-driven interface.

Java OOP License

πŸ“‹ Table of Contents

🎯 Overview

This project implements a school database management system that manages courses, faculty, students, and general staff through a hierarchical class structure. Built as part of CMP 158 at Lehman College, it demonstrates core computer science concepts including inheritance, polymorphism, file I/O, and exception handling.

Key Statistics

  • 7 Classes with inheritance relationships
  • 3-Level Inheritance Hierarchy
  • 15 CRUD Operations via menu interface
  • ~1,600 Lines of Code
  • 100% Functional with comprehensive error handling

✨ Features

Core Functionality

  • βœ… Create and manage courses, faculty, students, and general staff
  • βœ… Add courses to faculty teaching schedules
  • βœ… Enroll students in courses and track credits
  • βœ… Query system for specific faculty, students, or courses
  • βœ… Find min/max values (courses, credits, teaching loads)
  • βœ… Persistent data storage via file I/O
  • βœ… Menu-driven console interface with 15 operations

Advanced Features

  • βœ… Custom sorting via Comparable interface implementation
  • βœ… Object equality checking with overridden equals() methods
  • βœ… Formatted output via toString() overrides
  • βœ… Exception handling for file operations
  • βœ… Defensive programming with boundary checks
  • βœ… Static variable tracking for auto-generated IDs

πŸ—οΈ Class Structure

Inheritance Hierarchy

Person (Base Class)
β”œβ”€β”€ Employee
β”‚   β”œβ”€β”€ Faculty
β”‚   └── GeneralStaff
└── Student

Course (Standalone - implements Comparable<Course>)

Class Responsibilities

Person (Base Class)

  • Stores: name, birthYear
  • Implements: Comparable<Person>
  • Compares by: birthYear

Employee (extends Person)

  • Stores: deptName, employeeID (auto-generated)
  • Implements: inherited Comparable
  • Compares by: employeeID
  • Tracks: total number of employees (static)

Student (extends Person)

  • Stores: major, isGraduate, studentID (auto-generated), coursesTaken (ArrayList)
  • Implements: inherited Comparable
  • Compares by: total credits earned
  • Tracks: total number of students (static)

Faculty (extends Employee)

  • Stores: isTenured, coursesTaught (ArrayList)
  • Implements: inherited Comparable
  • Compares by: number of courses taught
  • Max capacity: 100 courses

GeneralStaff (extends Employee)

  • Stores: duty (job responsibility)
  • Implements: inherited Comparable
  • Inherits comparison from Employee

Course (Standalone)

  • Stores: isGraduateCourse, courseDept, courseNum, numCredits
  • Implements: Comparable<Course>
  • Compares by: courseNum

πŸš€ Getting Started

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Any Java IDE (IntelliJ IDEA, Eclipse, VS Code) or command line

Installation

  1. Clone the repository
git clone https://github.com/FidelAP-19/School-Database-System.git
cd School-Database-System
  1. Compile the project
javac *.java
  1. Run the application
java Main

Input File Format

Create a file named SchoolDB_Initial.txt with the following format:

Course: true,777,CMP,4
Faculty: John Smith,1980,Computer Science,true
Student: Jane Doe,2000,Computer Science,false
GeneralStaff: Bob Johnson,1975,Facilities,Maintenance

Format Rules:

  • Each line starts with object type: Course:, Faculty:, Student:, or GeneralStaff:
  • Fields are comma-separated
  • Boolean values: true or false

πŸ’» Usage

Menu Options

When you run the program, you'll see a menu with 15 operations:

=== MENU ===
1.  Create 3 New Courses
2.  Create 3 New Faculty
3.  Create 3 New General Staff
4.  Create 3 New Students
5.  Add 2 Courses to Faculty
6.  Add 2 Courses to Student
7.  Add Array of 2 Courses to Faculty
8.  Add Array of 2 Courses to Student
9.  Get Course from Faculty by Index
10. Get Course from Student by Index
11. Query Faculty for Course
12. Faculty with Most/Least Courses
13. Find Min/Max Course
14. Student with Most/Least Credits
15. Display All Data
0.  Exit and Save

Example Usage

Creating a New Course:

Enter choice: 1

--- Enter 3 New Courses ---
Course 1:
Are you a Graduate course? (true/false): false
Enter Course Number: 168
Enter Course Department: CMP
Enter Number of Credits: 4

Adding Courses to a Student:

Enter choice: 6

Which student? (Enter index): 0
Which course? (Enter index): 0
Course added successfully!

πŸ”§ Technical Highlights

Object-Oriented Design

Inheritance Hierarchy

  • 3-level deep inheritance demonstrating class relationships
  • Proper use of super() for parent class initialization
  • Method overriding for specialized behavior

Polymorphism

// Collections can hold parent type with child objects
ArrayList<Person> people = new ArrayList<>();
people.add(new Student("Alice", 2000, "CS", false));
people.add(new Employee("Bob", 1985, "IT"));

Encapsulation

  • All fields are private
  • Public getters/setters for controlled access
  • Defensive copying where appropriate

Data Structures

ArrayList Usage

private ArrayList<Course> coursesTaught;  // Faculty's courses
private ArrayList<Course> coursesTaken;   // Student's courses

Benefits:

  • Dynamic sizing (no fixed array limits)
  • Built-in methods (add, get, size)
  • Type safety with generics

File I/O & Exception Handling

try {
    FileInputStream fbs = new FileInputStream("SchoolDB_Initial.txt");
    Scanner inFS = new Scanner(fbs);
    // Process file...
    inFS.close();
} catch (FileNotFoundException e) {
    System.out.println("Cannot find file");
} catch (IOException e) {
    System.out.println("Error reading file");
}

Custom Sorting with Comparable

@Override
public int compareTo(Student other) {
    int thisCreditTotal = calculateTotalCredits();
    int otherCreditTotal = other.calculateTotalCredits();
    
    if (thisCreditTotal > otherCreditTotal) return 1;
    if (thisCreditTotal < otherCreditTotal) return -1;
    return 0;
}

Defensive Programming

Boundary Checking:

public Course getCourseTaken(int index) {
    if (index < 0 || index >= coursesTaken.size()) {
        return null;  // Safe return instead of crash
    }
    return coursesTaken.get(index);
}

Capacity Limits:

public void addCourseTaught(Course course) {
    if (coursesTaught.size() < 100) {  // Prevent overflow
        coursesTaught.add(course);
    }
}

Static Variables for ID Generation

public class Student extends Person {
    static private int numStudents = 0;  // Shared across all instances
    private int studentID;
    
    public Student() {
        numStudents++;                    // Increment counter
        studentID = numStudents;          // Auto-generate unique ID
    }
}

πŸ“š What I Learned

Core Concepts

  • βœ… Multi-level Inheritance - Building complex class hierarchies
  • βœ… Polymorphism - Using parent types to reference child objects
  • βœ… Encapsulation - Protecting data with private fields and public methods
  • βœ… Abstraction - Separating interface from implementation

Java-Specific Skills

  • βœ… Comparable Interface - Custom sorting logic
  • βœ… Method Overriding - equals(), toString(), compareTo()
  • βœ… ArrayList Collections - Dynamic data structures
  • βœ… File I/O - Reading/writing persistent data
  • βœ… Exception Handling - Graceful error recovery
  • βœ… Static vs Instance - Understanding class-level vs object-level data

Software Engineering Practices

  • βœ… Code Organization - Logical class structure
  • βœ… Defensive Programming - Null checks, boundary validation
  • βœ… User Input Validation - Preventing invalid data
  • βœ… Documentation - Clear comments and method signatures

Problem-Solving

  • βœ… String Parsing - Converting file data to objects
  • βœ… Data Validation - Ensuring data integrity
  • βœ… Menu-Driven Architecture - Building interactive applications
  • βœ… Algorithm Design - Finding min/max, calculating totals

πŸŽ“ Academic Context

Course: CMP 158 - Programming Methods II
Institution: Lehman College, City University of New York (CUNY)
Semester: Fall 2024

This project served as the capstone assignment, demonstrating mastery of:

  • Object-oriented programming principles
  • Java collections framework
  • File I/O and exception handling
  • Software design and architecture

πŸ“ Project Structure

School-Database-System/
β”œβ”€β”€ Person.java              # Base class for all people
β”œβ”€β”€ Employee.java            # Base class for employees
β”œβ”€β”€ Student.java             # Student class with course tracking
β”œβ”€β”€ Faculty.java             # Faculty with teaching assignments
β”œβ”€β”€ GeneralStaff.java        # General staff with duties
β”œβ”€β”€ Course.java              # Course information
β”œβ”€β”€ Main.java                # Entry point (basic version)
β”œβ”€β”€ Driver_SchoolDB.java     # Full menu-driven application
β”œβ”€β”€ SchoolDB_Initial.txt     # Sample input data
└── README.md                # This file

🀝 Contributing

This is an educational project, but feedback and suggestions are welcome!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/improvement)
  5. Open a Pull Request

πŸ“„ License

This project is open source and available under the MIT License.

πŸ‘€ Author

Fidel Perez

πŸ™ Acknowledgments

  • Institution: Lehman College, City University of New York (CUNY)
  • Course: Programming Methods II

⭐ If you found this project helpful or interesting, please consider giving it a star!


Built with β˜• and dedication to learning software engineering

About

Java-based database management system demonstrating OOP principles

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages