A menu-driven Java console application for managing hotel room bookings, check-ins, and check-outs — with dual persistence to MySQL and flat files.
This project simulates the day-to-day front-desk operations of a small hotel with 10 rooms. It demonstrates core object-oriented programming concepts — inheritance, polymorphism, and encapsulation — through a room class hierarchy, and integrates with a MySQL database via JDBC while also writing human-readable records to text files.
- Room catalog with inheritance — a base
Roomclass extended byStandardRoom($100/night),DeluxeRoom($150/night), andSuiteRoom($200/night) - Room booking with guest details, check-in date, and stay duration
- Check-in / check-out flow with total cost calculated as price x nights
- Live room status display showing type, price, availability, and current guest
- Robust input validation — guest names (alphabetic, min 2 chars), contact numbers (exactly 10 digits), ISO dates (
YYYY-MM-DD, no past dates), and positive stay durations - Dual persistence
- Bookings inserted into a MySQL
bookingstable via JDBCPreparedStatement - Bookings appended to
booking_data.txt; room status snapshot written toroom_status.txton exit
- Bookings inserted into a MySQL
Hotelmanagement/
├── management/
│ ├── HotelManagementSystem.java # Main class: menu loop, DB + file persistence
│ └── mysql-connector-j-8.2.0.jar # JDBC driver
├── room/
│ ├── Room.java # Base class: booking, check-in/out, cost logic
│ ├── StandardRoom.java # $100/night
│ ├── DeluxeRoom.java # $150/night
│ ├── SuiteRoom.java # $200/night
│ └── CheckIn.java # Check-in date + stay duration
├── booking_data.txt # Sample booking records
└── room_status.txt # Sample room status snapshot
- Java (java.time, java.io, JDBC)
- MySQL with MySQL Connector/J 8.2.0
- File I/O for plain-text record keeping
- JDK 8+
- A running MySQL server
Create the database and table expected by the app:
CREATE DATABASE hotelmanagementsystem;
USE hotelmanagementsystem;
CREATE TABLE bookings (
room_number INT,
guest_name VARCHAR(100),
guest_contact VARCHAR(10),
check_in_date DATE,
stay_duration INT
);Update DB_URL, DB_USERNAME, and DB_PASSWORD in management/HotelManagementSystem.java to match your local MySQL credentials.
From the repository root:
javac -cp management/mysql-connector-j-8.2.0.jar management/HotelManagementSystem.java room/*.java
java -cp .:management/mysql-connector-j-8.2.0.jar management.HotelManagementSystem(On Windows, use ; instead of : in the classpath.)
Then follow the on-screen menu:
Hotel Management System Menu:
1. Display Room Status
2. Book a Room
3. Check In
4. Check Out
5. Exit