Personal project · 2025

University Library System

The borrower carries the rules, not the front desk.

A console library system in Java where adults, students and children each borrow under their own rules, built for my object-oriented programming module.

Stack
Java 17, JUnit 4, CSV files, UML
Module
Object-oriented programming
Tests
7 unit tests, 17 console tests

Why it matters

Coursework for my object-oriented programming module: a console library where adults, students and children borrow books, CDs, DVDs and audiobooks under different limits and loan lengths. There is no database and no graphical interface, in line with the brief, so the work is in the design. The real question is where the rules live. Keep them at the front desk, in one controller that checks who is asking, and every new kind of user means editing it; give each kind of borrower its own class, and the desk never has to ask.

How it works

CSV files

The catalogue, one file per media type

books · cds · dvds · audiobooks

Data loader

Turns each line into an object

Book · CD · DVD · Audiobook

Total products: 35

Login menu

Pick adult, child or student

one demo user per role

Logged in as Student: Oriol

Borrow menu

Only the categories that role may take

student: books, audiobooks

  • category chosen
  • product ID typed in

LibrarySystem

Finds the product, checks it is in

controller · findProductById

  • product found
  • not checked out

User subclass

Each role checks its own rules

adult 10 · student 5 · child 3

  • under its limit
  • guardian, if a child
  • loan policy chosen

Loan

Due date set by the policy

LocalDate · reminders

Borrowed successfully: The Hobbit

CatalogueRequestRulesEvery box is something I built.

Decisions I made

  1. Each borrower carries its own rules

    AdultUser, Student and ChildUser each override the same borrow method with their own limit of ten, five or three items. Students and children also get their own loan length, and a child cannot borrow without a guardian. LibrarySystem hands every request to whoever is asking and never checks their type. I weighed putting the rules in the controller, or in one method with a branch per user type, and turned both down.

    Trade-off. Which categories each role may see is still decided in the menu, with a type check per role, so that rule sits outside the user classes. The limits are also fixed in code, not read from data.

  2. The loan is made where the borrowing happens

    LibrarySystem used to create each loan. A JUnit test that had an adult borrow ten items then found them holding no loans at all, so the limit could never be reached. I moved loan creation into the user's own borrow method, which every borrow passes through, whoever starts it.

    Trade-off. Loans now live in two lists, the user's and the library's, and each borrow and return must update both.

  3. The catalogue lives in CSV files

    Books, CDs, DVDs and audiobooks each have their own CSV file, read into objects when the program starts. Adding a title means adding a line, not changing code.

    Trade-off. Nothing is written back, so loans last only until the program closes.

Gallery

Final UML class diagram: LibrarySystem, the abstract User and Product classes with their subclasses, Loan and Policy
The project in IntelliJ, with the seven JUnit test classes in their own test folder
AdultBorrowLimitTest failing: ten borrows print as successful, but the adult holds 0 loans instead of 10
AdultBorrowLimitTest passing after the fix: ten borrows succeed and the next five are refused at the limit

The full engineering is on GitHub.