Hotel Reservation System using java

Introduction
This project was developed in Java and has a JavaFX Graphical User Interface (GUI) which provides an easy and intuitive experience for hotel receptionists to manage reservations in an easy manner. The purpose of the program is to help hotel receptionists perform the process of room reservations, check-in, check-out, and customers’ data easily. The main goal of this project is to make it easy for hotel staff to manage day-to-day operations. With the growing need for effective hotel management software, this application responds to the demand for an easy and reliable solution.
Main application features are:
- Room Management: Filtering and searching available rooms according to customer requirements, e.g., luxury suites.(SourceCodester)
- Customer Management: See and group customers as booked, old, or current to enhance customer service.
- Check-In and Check-Out: Streamline the check-in and check- out operations, keeping room availability updated in real-time.
- User Interface: A simple Graphical User Interface (GUI) was built with JavaFX, which should make it easy for anyone in the hotel to use without any extensive training.
The application is fairly simple and functional, which certainly makes it a good web application for small to medium sized hotels that want an easy way to digitize their reservations without the expense and complications of a larger reservation system.
Required Modules or packages
- Java Development Kit(JDK 8 or later) : The application was developed using java.
- JavaFX : used for building the GUI .If you are suing java 11 or later you will have to download JavaFX separately, as its not included by default Any longer.
- Eclipse IDE: The project is going to be set up for Eclipse but you can use IntelliJ IDEA or NetBeans with some configuration.
To set up JavaFX with your IDE: Download JavaFX SDK: Visit the Gluon website and download the appropriate JavaFX SDK for your operating system.
Set Up JavaFX in Your IDE:
Project > Properties > Java Build Path
Libraries > Add External JARs, and add the JavaFX SDK lib files.
Set VM arguments to include the JavaFX modules.
IntelliJ IDEA:
File > Project Structure > Libraries, and add the JavaFX SDK.
Set the VM options in Run > Edit Configurations.
Set Environment Variables (Optional) – To make it easier for you, set environment variables JAVA_HOME, and PATH to include Java & JavaFX directories.
How to Run the Code
Clone the Repository : git clone https://github.com/NyanSwanAung/Hotel-Reservation-System.git
Import the Project into Your IDE:
Open Eclipse and go to File > Import.
Choose Existing Projects into Workspace and click Next. Navigate to the folder of the cloned repository and select it. Click Finish to import the project.
IntelliJ IDEA:Open IntelliJ IDEA and choose Open. Go to the folder of the cloned repository and open it. Set up the project SDK and JavaFX libraries as appropriate.
Set up JavaFX: Make sure that JavaFX is set up correctly in your IDE. See the “Required Modules or Packages” section for instructions.
Build and Run the Project:
Go to the Main.java file in the src/com/mainview package.
Right-click Main.java and choose Run As > Java Application (in Eclipse) or click the Run button (in IntelliJ IDEA).
The application should start, and show the login screen.(GitHub)
Using the Application:
- Login: Use the given credentials to enter the main dashboard.
- Dashboard: Move through features such as Check-In, Check-Out, Room Management, and Customer List.
- Room Management: See available rooms, sort by preferences, and update room statuses.
- Customer List: See customer details, sort by current, old, or booked customers, and manage records.
- Check-In/Check-Out: Process customer check-ins and check-outs, changing the room status accordingly.(GitHub)
Make sure all the necessary libraries are properly set up, and the app should be fine. In case of trouble, check the project’s GitHub repository for troubleshooting and assistance
Get Discount on Top Educational Courses
Code Explanation
Main.java : Application entry point. It loads the Reserve.fxml layout file (which defines the user interface). Sets up the main application window (title, size). Displays the GUI.
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Reserve.fxml"));
primaryStage.setTitle("Hotel Reservation System");
primaryStage.setScene(new Scene(root));primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Customer.java: This is a plain old java object that contains data about a customer. It is a data structure that holds information about a customer and used to present customer information in tables or forms. Encapsulates customer attributes with appropriate getter/setter methods.
public class Customer {
private String name;
private String phone;
private String email;
private String roomNumber;
private String checkInDate;
private String checkOutDate;
// Constructors, Getters, and Setters
}
Room.java: This class stores information about each hotel room. Represents rooms and their availability and is used to populate room lists and room search results. Allows for the dynamic change of room availability when booked.
public class Room {
private String roomNumber;
private String roomType;
private boolean isAvailable;
private double price;
// Constructors, Getters, Setters
}
reserve.xml: this defines the UI for room reservations using XML. A table for showing room info (TableView) Text fields for entering customer details Buttons for actions like Reserve, Check-In, Check-Out
<TableView fx:id="roomTable" ... />
<TextField fx:id="nameField" />
<Button text="Reserve" onAction="#handleReserve" />
ReserveController.java: This java class connects the Reserve.fxml UI to logic.Connects UI events (like button clicks) to backend logic. Validates form data. Communicates with the database class to store or retrieve data.Updates UI components like table views after changes.
public class ReserveController {
@FXML private TextField nameField;
@FXML private TableView<Room> roomTable;
public void handleReserve(ActionEvent event) {
// Get selected room
Room selectedRoom = roomTable.getSelectionModel().getSelectedItem();
// Get customer details
String name = nameField.getText();
// Save to database
Database.insertCustomer(name, selectedRoom.getRoomNumber());
// Update room status
selectedRoom.setAvailable(false);
roomTable.refresh();
}
}
Database.java: Opens and manages connections to the SQLite database. Executes SQL queries (INSERT, SELECT, UPDATE). Provides methods used by the controller.
public class Database {
public static void insertCustomer(String name, String roomNumber) {
String sql = "INSERT INTO customers (name, roomNumber) VALUES (?, ?)";
try (Connection conn = DriverManager.getConnection(DB_URL);
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, name);
pstmt.setString(2, roomNumber);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
CustomerList.fxml: This screen shows a TableView of all customers and includes filters. It is used for viewing and filtering customers based on their reservation status.Dynamic updates as users check in or out.
<ChoiceBox fx:id="statusFilter" />
<TableView fx:id="customerTable">
<columns>
<TableColumn text="Name" fx:id="nameCol"/><TableColumn text="Room" fx:id="roomCol"/>
</columns>
</TableView>
Source code:


