Hotel Management System

Hotel Management System

Jigar Bhoye / November 28, 2023

JavaSerializationFile I/OObject-Oriented Programming

Hotel Management System

This Java program implements a basic hotel management system that allows users to:

  • View room details and features.
  • Check room availability.
  • Book rooms.
  • Order food.
  • Checkout from rooms and generate bills.
  • Persist data between sessions using file serialization.

1. Introduction

This project simulates a simplified hotel management system using Java. It allows users to interact with different room types, manage bookings, order food, and checkout. The system utilizes file serialization to save and load data, providing a basic form of data persistence between program executions.

2. Features

  • Room Management:
    • Handles four types of rooms: Luxury Double, Deluxe Double, Luxury Single, and Deluxe Single.
    • Displays room features (beds, AC, breakfast, price).
    • Checks and displays the number of available rooms of each type.
  • Booking:
    • Allows users to book available rooms.
    • Collects customer details (name, contact, gender).
    • For double rooms, collects information for a second guest as well.
  • Food Ordering:
    • Allows customers to order from a predefined menu (Sandwich, Pasta, Noodles, Coke).
    • Tracks food orders associated with each room.
  • Checkout & Billing:
    • Checks out guests from their rooms.
    • Generates a detailed bill, including room charges and food costs.
  • Data Persistence:
    • Saves and loads all booking and order data to/from a file named "backup" using Java serialization. This ensures data is preserved between sessions.
  • Simple Menu Driven Interface:
    • Provides an easy to use text-based interface for interacting with the system.

3. Classes

Food

  • Represents a food item ordered.
  • Contains itemno (item ID), quantity, and price.
  • The price is calculated based on item ID and quantity.
  • Implements Serializable for data persistence.

Singleroom

  • Represents a single occupancy room.
  • Contains name, contact, gender, and an ArrayList of Food items.
  • Implements Serializable.

Doubleroom

  • Extends Singleroom to represent double occupancy rooms.
  • Contains additional customer details: name2, contact2, and gender2.
  • Implements Serializable.

NotAvailable

  • A custom exception class used to indicate that a requested room is not available.

holder

  • A container class that holds arrays of Doubleroom and Singleroom objects.
  • This class represents the entire hotel's inventory of rooms.
  • Implements Serializable.

Hotel

  • Contains the main logic for the hotel management system.
  • Includes static methods for:
    • CustDetails: To gather customer info and assign it to a room
    • bookroom: To book a room
    • features: To show the features of different room types.
    • availability: To display how many rooms of a certain type are free.
    • bill: To generate a bill for a room.
    • deallocate: To remove a booking from the system.
    • order: To add food orders to a booking.

write

  • Implements Runnable for writing the holder object into the backup file.

assignment

  • The main class that contains the main method for executing the program.
  • This class handles loading data from file if the "backup" file exists, presents the main menu, processes user choices, and provides data persistance.

4. Usage

Once the program is running, you will see the main menu. Here's how to use each option:

  1. Display Room Details:
    • Choose option 1 from the menu.
    • Select the room type (1-4) to view its features.
  2. Display Room Availability:
    • Choose option 2 from the menu.
    • Select the room type (1-4) to see the number of available rooms.
  3. Book a Room:
    • Choose option 3 from the menu.
    • Select the desired room type (1-4).
    • Choose a room number from available rooms.
    • Enter customer details as prompted.
  4. Order Food:
    • Choose option 4 from the menu.
    • Enter the room number.
    • Select food items by ID from the menu and quantity.
    • You can order multiple items.
  5. Checkout:
    • Choose option 5 from the menu.
    • Enter the room number.
    • Confirm the checkout to receive the bill and deallocate the room.
  6. Exit:
    • Choose option 6 from the menu to terminate the program and save the current bookings.

5. Data Persistence

  • The system uses Java's serialization to persist the holder object, which contains the room booking information, to a file named "backup."
  • When the application starts, it attempts to load the saved holder object from this "backup" file if the file is present. This means that any bookings or food orders made in a previous session will still be active when you restart the program.

6. Error Handling

  • Invalid Room Numbers: The program validates room numbers.
  • Room Not Available: If a user tries to book an already booked room, a NotAvailable exception is thrown.
  • Invalid Menu Options: User input for menu choices, food items and quantities are also validated.
  • NullPointerException: In ordering, if you try to add food to a room that hasn't been booked, the system catches this exception.

7. Known Limitations

  • Basic Text Interface: The user interface is entirely text-based.
  • Limited Functionality: Does not include complex features like search and sorting of bookings, or dynamic room price management, or cancellation feature.
  • Static Room Allocation: Rooms are pre-defined at program start.
  • Basic Menu: Food menu is simple and static.
  • Single File Persistence: All data is stored in a single file.

Get in Touch

Want to chat? Just shoot me a text on twitter or email me directly at jigarbhoye04@gmail.com or contact