My Personal Logo Java Logo

Hotel Management System

Using Java - CSE231 - Spring 2025 Project

UML Diagram
UML Diagram
Code Preview
Code
UI Preview [Using JavaFX]
UI

UI-preview

Project Requirements

Create a UML diagram for the project

Show Examples of Encapsulation

Most of the data fields are private or accessible through the same package or only accessible through public methods (Getters and Setters).

// Private field - only accessible within the class
private static String hotelName = "Grand";

// Public getter method - controlled access to private field
public static String getHotelName() {
return "Name: " + hotelName;
}

// Public setter method - controlled modification of private field
public static void setHotelName(String newName) {
if (newName != null && !newName.trim().isEmpty()) {
hotelName = newName;
}
}

Created an abstract class

Created an abstract hotel class [and most of the classes are extended from it for Example Booking > Guests > Rooms > Hotel]
I Did it so i can better visualize the System
not necessary for the system but it helped me to understand the system and imagine it better
Optional: Could have also implemented it an interface for discount system

How you sorted the rooms in the hotel?

The code didn't need sorting but i did it because it's required in the project requirements and to be 100% sure that the Rooms are sorted by number.
Why i didn't need sorting?

public Rooms() {
// Initialize hotel with 9 floors, 3 rooms per floor
for (int floor = 0; floor < 9; floor++) { // changed it to 9 to handle 9 single guests case
for (int i = 0; i < 3; i++) {
// Alternate between single and double rooms
allRooms.add(new Room(floor, i, i % 2 == 0)); // even index = double room
}
}
}

but i added a sorting method in the hotel class to sort the rooms by number to make sure everything is working fine

import java.util.Comparator; //first import Comparator
public void sortRooms() {
allRooms.sort(Comparator.comparingInt(Room::getRoomNumber)); // sort based on room number [ascending order]
}

// Display current status of all rooms
public void displayRoomStatus() {
sortRooms();
System.out.println("\n--- ROOM STATUS ---");
for (Room room : allRooms) {
System.out.println(room);
}
}

Create a report for the project

Create a demo for the project

In my you can create whatever scenario you want here is a demo for the project

Demo