0% found this document useful (0 votes)
7 views22 pages

Hotel MGMT System

The document outlines the design and implementation of a Hotel Management System, which includes classes for Room, Guest, Booking, and Hotel, along with features for managing bookings and guest information. Key functionalities include room management, reservation handling, and billing information display, utilizing principles of object-oriented programming such as encapsulation, inheritance, and polymorphism. The system also incorporates a user interface for booking, canceling reservations, and viewing booking history.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views22 pages

Hotel MGMT System

The document outlines the design and implementation of a Hotel Management System, which includes classes for Room, Guest, Booking, and Hotel, along with features for managing bookings and guest information. Key functionalities include room management, reservation handling, and billing information display, utilizing principles of object-oriented programming such as encapsulation, inheritance, and polymorphism. The system also incorporates a user interface for booking, canceling reservations, and viewing booking history.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

BSIT – 2D

Leader:

Fiesta, Justin Aaron

Members:

Repollo, Mary Hilareen

Leonin, Reynald

De Vera, John Kerwin

Hotel Management System

Objective: Design a system to manage hotel bookings and guest information.

Requirements:

• Classes and Objects: Implement classes for Room, Guest, Booking, and Hotel.

• Encapsulation: Use private fields with getter and setter methods.

• Inheritance: Create subclasses for SingleRoom, DoubleRoom, etc., extending Room.

• Polymorphism: Override methods to handle different room types and pricing.

• Interfaces: Define an interface Reservable with methods like makeReservation() and

cancelReservation().

• Collections: Use collections to manage rooms and bookings.

Features:

• Add and manage rooms.

• Book rooms and manage reservations.

• View guest information and booking history.


//ROOM CLASS

import java.time.LocalDate;

import java.util.ArrayList;

import java.util.List;

public class Room {

private int roomNumber;

private boolean isAvailable;

private double price;

private String roomType;

private List<LocalDate[]> bookedDates;

Room(int roomNumber, double price, String roomType){

setRoomNumber(roomNumber);

setPrice(price);

setRoomType(roomType);

setAvailable(true);

this.bookedDates = new ArrayList<>();

//getter and setter for Room Number

public int getRoomNumber() {

return roomNumber;

public void setRoomNumber(int roomNumber) {

this.roomNumber = roomNumber;

//getter and setter for Price


public double getPrice() {

return price;

public void setPrice(double price) {

this.price = price;

//getter and setter for roomtype;

public String getRoomType() {

return roomType;

public void setRoomType(String roomType) {

this.roomType = roomType;

//getter and setter for Availability

public boolean isAvailable() {

return isAvailable;

public void setAvailable(boolean isAvailable) {

this.isAvailable = isAvailable;

//once a room is booked, it checks if the check-in and check-out dates does not conflict to existing
booking dates

public boolean isAvailableForDates(LocalDate checkIn, LocalDate checkOut) {

for (LocalDate[] dates : bookedDates) {

LocalDate existingCheckIn = dates[0];

LocalDate existingCheckOut = dates[1];


if (!(checkOut.isBefore(existingCheckIn) || checkIn.isAfter(existingCheckOut))) {

return false; //it means that one or both of the dates overlap with the existing ones

return true;

//this method adds the booking dates to a list of booking dates for the room

public void addBookingDates(LocalDate checkIn, LocalDate checkOut) {

bookedDates.add(new LocalDate[]{checkIn, checkOut});

//this methods takes the check in and check out date from the given booking and removes it from the
bookedDates list

public void removeBookingDates(Booking booking){

LocalDate removeCheckIn = booking.getCheckInDate();

LocalDate removeCheckOut = booking.getCheckOutDate();

bookedDates.removeIf(dates ->

dates[0].equals(removeCheckIn) && dates[1].equals(removeCheckOut));

}
//ROOM SUBCLASS – SINGLE ROOM

public class SingleRoom extends Room{

SingleRoom(int roomNumber, double price){

super(roomNumber, price, "Single Room");

setAvailable(isAvailable());;

}
//ROOM SUBCLASS – DOUBLE ROOM

public class DoubleRoom extends Room{

DoubleRoom(int roomNumber, double price){

super(roomNumber, price, "Double Room");

}
//ROOM SUBCLASS – EXTENDED ROOM

public class ExtendedRoom extends Room{

ExtendedRoom(int roomNumber, double price ){

super(roomNumber, price, "Extended Room");

}
//GUEST CLASS

import java.util.List;

import java.util.ArrayList;

public class Guest {

private String name;

private String contactInfo;

private List<Booking> bookingHistory;

Guest(String name, String contactInfo){

setName(name);

setContactInfo(contactInfo);

this.bookingHistory = new ArrayList<>();

//getter and setter for Name

public String getName() {

return name;

public void setName(String name) {

this.name = name;

//getter and setter for Contact Info

public String getContactInfo() {

return contactInfo;

public void setContactInfo(String contactInfo) {

this.contactInfo = contactInfo;

}
//add booking to the guest's booking history

public void addBooking(Booking booking) {

bookingHistory.add(booking);

public void viewBookingHistory(){

if(bookingHistory.isEmpty()){

System.out.println("No booking history");

else{

System.out.println("Booking History for "+ name + ": ");

for(Booking booking : bookingHistory){

System.out.println(booking);

}
//BOOKING CLASS

import java.time.LocalDate;

import java.time.format.DateTimeFormatter;

import java.time.format.DateTimeParseException;

public class Booking {

private Guest guest;

private Room room;

private LocalDate checkInDate;

private LocalDate checkOutDate;

Booking(Guest guest, Room room, String checkInDate, String checkOutDate){

setGuest(guest);

setRoom(room);

setCheckInDate(checkInDate);

setCheckOutDate(checkOutDate);

//getter and setter for Guest

public Guest getGuest() {

return guest;

public void setGuest(Guest guest) {

this.guest = guest;

//getter and setter for Room

public Room getRoom() {

return room;

public void setRoom(Room room) {


this.room = room;

//getter and setter for CheckIn

public LocalDate getCheckInDate() {

return checkInDate;

public void setCheckInDate(String checkInDate) {

this.checkInDate = LocalDate.parse(checkInDate);

//getter and setter for CheckOut

public LocalDate getCheckOutDate() {

return checkOutDate;

public void setCheckOutDate(String checkOutDate) {

this.checkOutDate = LocalDate.parse(checkOutDate);

//to check how long the guest will stay

public int getNumberOfNights(){

if(checkOutDate.compareTo(checkInDate)==0){

return 1; //to accommodate same-day check-in and check-out

}else{

return checkOutDate.compareTo(checkInDate);

//to calculate the total amount due

public double getTotalAmount(){


return getNumberOfNights() * room.getPrice();

public static boolean isValidDate(String dateStr) {

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

try {

LocalDate.parse(dateStr, formatter);

return true;

} catch (DateTimeParseException e) {

return false;

public String toString() {

return "Booking{" +

"Guest: " + guest.getName() +

", Room: " + room.getRoomType() + " (Room " + room.getRoomNumber() + ")" +

", Check In Date: " + checkInDate +

", Check Out Date: " + checkOutDate +

'}';

}
//RESERVABLE INTERFACE

import java.time.LocalDate;

public interface Reservable {

void makeReservation(Guest guest, Room room, LocalDate checkInDate, LocalDate checkOutDate);

void cancelReservation(Guest guest, int roomNumber);

}
//HOTEL CLASS

import java.util.ArrayList;

import java.util.List;

import java.time.LocalDate;

public class Hotel {

//initialize Lists or the Collections for the rooms and bookings

private List<Room> rooms;

private List<Booking> bookings;

//constructor for class hotel

public Hotel(){

this.rooms = new ArrayList<>();

this.bookings = new ArrayList<>();

//method to add room to the collection

public void addRoom(Room room){

rooms.add(room);

//traverse the room list for a specific room type

public Room findAvailableRoom(String roomType, String checkInDate, String checkOutDate) {

for (Room room : rooms) {

if (room.getRoomType().equalsIgnoreCase(roomType) &&

room.isAvailableForDates(LocalDate.parse(checkInDate), LocalDate.parse(checkOutDate))) {

return room; // Found an available room for the requested dates

}
return null; // No room available

//method for getting a certain booking depending on the guest name and their room number

public Booking getBooking(String guestName, int roomNumber){

for(Booking booking: bookings){

if(booking.getGuest().getName().equals(guestName) && booking.getRoom().getRoomNumber()==


roomNumber){

return booking;

return null;

//method overloading getBooking, with different parameter to get the booking using the guest's name
and contact info

public Booking getBooking(String guestName, String guestEmail){

for(Booking booking: bookings){

if(booking.getGuest().getName().equals(guestName) &&
booking.getGuest().getContactInfo().equals(guestEmail)){

return booking;

return null;

public void removeBooking(Booking booking){

bookings.remove(booking);

}
//implemented from the reservable interface

//create a booking based on guest, room type, check-in and check-out dates

public void makeReservation(Guest guest, String roomType, String checkInDate, String checkOutDate){

Room room = findAvailableRoom(roomType,checkInDate,checkOutDate); //setting the room based


on the traversed available room

if(room != null){ //proceeds with the booking if the room object is not null

Booking booking = new Booking(guest, room, checkInDate, checkOutDate); // creates a booking


object

bookings.add(booking); //adds the booking made to the list of bookings

guest.addBooking(booking); // adds the booking under guest who made it

room.setAvailable(false); //modifies the availability of the room to unavailable

room.addBookingDates(LocalDate.parse(checkInDate),LocalDate.parse(checkOutDate)); //parses
the dates and adds them to the booked dates

System.out.println("Reservation made for " + room.getRoomType() + " (Room " +


room.getRoomNumber() + ")");

System.out.println("You will be staying for "+ booking.getNumberOfNights() + " night/s");

}else{

System.out.println("No available " + roomType + " for the selected dates"); // prints if there are no
available room type based on the guest's preference

//cancels a reservation or booking based on guest name and room number

public void cancelReservation(String guestName, int roomNumber){

Booking toCancel = getBooking(guestName, roomNumber); // sets the booking to be canceled


based on the given guest name and room number

if(toCancel != null){

bookings.remove(toCancel); //removes the booking in the bookings list

toCancel.getRoom().removeBookingDates(toCancel);
toCancel.getRoom().setAvailable(true); // sets the as room available

System.out.println("Reseration on room " + roomNumber + " has been canceled by guest " +
guestName);

}else{

System.out.println("No booking found for guest " + guestName + " under Room "+ roomNumber);

//displays the billing information based on the guest name and room number

public void showBillingInfo(String guestName, int roomNumber){

Booking settleBooking = getBooking(guestName, roomNumber); // sets the booking to be settled


based on the given guest name and room number

//displays all information associated to the booking

if(settleBooking !=null){

System.out.println("Settling bill for guest "+ guestName);

System.out.println("Room Number: Room " + roomNumber);

System.out.println("Room Type: " + settleBooking.getRoom().getRoomType());

System.out.println("Rate(per night): " + settleBooking.getRoom().getPrice());

System.out.println("Number of Nights: " + settleBooking.getNumberOfNights());

System.out.println("Total Amount Due: "+ settleBooking.getTotalAmount());

System.out.println(" ");

}else{

System.out.println("No booking under "+ guestName + " and Room number" + roomNumber);

}
//MAIN CLASS

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Hotel hotel = new Hotel();

hotel.addRoom(new SingleRoom(101, 50.0));

hotel.addRoom(new DoubleRoom(102, 100.0));

hotel.addRoom(new ExtendedRoom(103,300.0));

boolean running = true;

String choice;

while(running){

System.out.println("1. Book a room");

System.out.println("2. Cancel a reservation");

System.out.println("3. Settle bills");

System.out.println("4. View booking history");

System.out.println("5. Exit");

System.out.print("Select transaction method(1-5): ");

int selected = sc.nextInt();

sc.nextLine();

switch(selected){

case 1:

System.out.println();

System.out.println("Booking A Room");

System.out.print("Enter your name: ");


String name = sc.nextLine();

System.out.print("Enter your contact email: ");

String email = sc.nextLine();

Guest guest = new Guest(name,email);

System.out.print("Specify room type(Single Room/Double Room/Extended Room): ");

String roomType = sc.nextLine();

if(roomType.equals("Single Room")||roomType.equals("Double
Room")||roomType.equals("Extended Room")){

System.out.print("Enter check-in date(yyyy-mm-dd): ");

String checkInDate = sc.nextLine();

System.out.print("Enter check-out date(yyyy-mm-dd): ");

String checkOutDate = sc.nextLine();

if(Booking.isValidDate(checkInDate)&&Booking.isValidDate(checkOutDate)&&
checkOutDate.compareTo(checkInDate)>=0){

hotel.makeReservation(guest, roomType, checkInDate, checkOutDate);

}else{

System.out.println("Invalid date/s");

break;

}else{

System.out.println("Incorrect Room Type specified");

break;

System.out.println();

System.out.print("Would you like to make another transaction?(Y/N): ");

choice = sc.nextLine();
if(choice.equals("Y")){

break;

}else{

running = false;

break;

case 2:

System.out.println();

System.out.println("Canceling A Reservation");

System.out.print("Enter the guest's name: ");

String cancelName = sc.nextLine();

System.out.print("Enter the room number you wish to cancel reservations on: ");

int roomNumber = sc.nextInt();

sc.nextLine();

hotel.cancelReservation(cancelName, roomNumber);

System.out.println();

System.out.print("Would you like to make another transaction?(Y/N): ");

choice = sc.nextLine();

if(choice.equals("Y")){

break;

}else{

running = false;

break;

case 3:
System.out.println();

System.out.println("Settling Bills");

System.out.println("Enter the guest's name: ");

String settleName = sc.nextLine();

System.out.println("Enter room number: ");

int settleRoomNumber = sc.nextInt();

hotel.showBillingInfo(settleName, settleRoomNumber);

System.out.println("Enter the amount paid: ");

double amountPaid = sc.nextDouble();

sc.nextLine();

if(amountPaid>=hotel.getBooking(settleName, settleRoomNumber).getTotalAmount()){

System.out.println("Payment Successful. Change: " + (amountPaid -


hotel.getBooking(settleName, settleRoomNumber).getTotalAmount()));

hotel.getBooking(settleName, settleRoomNumber).getRoom().setAvailable(true);

hotel.removeBooking(hotel.getBooking(settleName, settleRoomNumber));

}else{

System.out.println("Insufficient funds");

System.out.println();

System.out.print("Would you like to make another transaction?(Y/N): ");

choice = sc.nextLine();

if(choice.equals("Y")){

break;

}else{

running = false;

break;
case 4:

System.out.println();

System.out.println("Viewing Booking History");

System.out.print("Enter your name: ");

String historyName = sc.nextLine();

System.out.print("Enter your contact email: ");

String historyEmail = sc.nextLine();

hotel.getBooking(historyName, historyEmail).getGuest().viewBookingHistory();

System.out.println();

System.out.print("Would you like to make another transaction?(Y/N): ");

choice = sc.nextLine();

if(choice.equals("Y")){

break;

}else{

running = false;

break;

case 5:

running = false;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy