Study a three-layer Java app with data classes, a controller, and a JDBC database layer.
Practice writing prepared statements and try-with-resources blocks against a real MySQL server.
Use as a portfolio piece for a junior Java low-level design interview.
Extend the schema with a rentals table and add return-by-date logic.
Needs JDK 8+, a running MySQL server, and the MySQL Connector/J driver on the classpath before the console app can start.
This repository is a small Java practice project that builds a console-style car rental system. The author frames it as a low-level design exercise that goes beyond the usual in-memory examples by saving the state of the rental into a real MySQL database. The point of the project is to show how object-oriented code, clean separation between business logic and database code, and a few defensive habits fit together in one place. The code is split into three layers. The first layer holds the data classes. A Car class represents a vehicle in the fleet, with brand, model name, base price, and an availability state. A Customer class holds customer details and how many days they want to rent for. A RentalReceipt class records a finished transaction by linking a customer to a car along with the total price. The second layer is a RentalSystem class that acts as the controller. It coordinates the workflow, holds temporary state in HashMaps, and decides when to update records. The third layer is a Database_Control class that talks to MySQL directly through JDBC. The README highlights a few specific habits the author wanted to demonstrate. All database access goes through prepared statements with placeholders rather than building queries by string concatenation, which the author calls SQL injection immunity. Every block that opens a connection, a statement, or a result set uses Java's try-with-resources pattern so those resources close even when a query fails. The code also handles edge cases like an empty fleet or a missing record so the console app does not crash with an unhandled exception. Running it locally needs JDK 8 or higher, a MySQL server, and the MySQL Connector/J driver on the classpath. The README includes the SQL script that creates the database called local and two tables, one for cars and one for customers. The cars table has an auto-incrementing id, brand, car name, base price, and a rental_status column that defaults to AVAILABLE. The customers table has an id, a customer name, and a days field. The project is small and personal in scope. It does not claim to be a production system; it is meant as a study piece showing one developer's take on encapsulation, single responsibility, and safe resource handling in a Java application that touches a database.
Generated 2026-05-22 · Model: sonnet-4-6 · Verify against the repo before relying on details.