0% found this document useful (0 votes)
34 views7 pages

Dsa Project Code

The document outlines a project for a Hotel Room Management System developed in Java, featuring classes for room management, customer details, and reservations. It includes functionalities for viewing available rooms, reserving rooms, managing a waitlist, and handling meal orders. The system utilizes data structures such as a binary search tree for room management and a queue for waitlist management.

Uploaded by

23-se-114
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views7 pages

Dsa Project Code

The document outlines a project for a Hotel Room Management System developed in Java, featuring classes for room management, customer details, and reservations. It includes functionalities for viewing available rooms, reserving rooms, managing a waitlist, and handling meal orders. The system utilizes data structures such as a binary search tree for room management and a queue for waitlist management.

Uploaded by

23-se-114
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Data Structure and Algorithm(PROJECT)

Section:B
Project name:
HOTEL ROOM MANAGEMENT SYSTEM

Submitted By :
MUSHAB FAIQ ABBASI(23-SE-118)
NAIMAT ULLAH KHAN (23-SE-066)
ARMAGHAN MALIK (23-SE-051)
SOLAN SAJID (23-SE-105)

SUBMITTED TO:
MA'M MOMINA BEHAIZAD
-: Project CODE :-

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

class Main {
// Room Node Class (BST Node)
static class RoomNode {
int roomNumber;
String type;
double pricePerNight;
boolean isAvailable;
boolean isUnderMaintenance;
RoomNode left, right; // For BST

RoomNode(int roomNumber, String type, double pricePerNight) {


this.roomNumber = roomNumber;
this.type = type;
this.pricePerNight = pricePerNight;
this.isAvailable = true;
this.isUnderMaintenance = false;
this.left = this.right = null;
}

void displayDetails() {
System.out.println("Room " + roomNumber + " - " + type +
" - Rs. " + pricePerNight + " per night - " +
(isAvailable ? "Available" : "Not Available") +
(isUnderMaintenance ? " (Under Maintenance)" : ""));
}
}

// Customer Class
static class Customer {
String name, phoneNumber, email;
int roomNumber;

Customer(String name, String phoneNumber, String email, int


roomNumber) {
this.name = name;
this.phoneNumber = phoneNumber;
this.email = email;
this.roomNumber = roomNumber;
}

void displayDetails() {
System.out.println("Customer Details:");
System.out.println(" Name: " + name);
System.out.println(" Phone: " + phoneNumber);
System.out.println(" Email: " + email);
System.out.println(" Room Number: " + roomNumber);
}
}

// Reservation Class
static class Reservation {
Customer customer;
RoomNode room;
LinkedList<String> meals; // Linked List for meals
double totalBill;
int days;

Reservation(Customer customer, RoomNode room, int days) {


this.customer = customer;
this.room = room;
this.meals = new LinkedList<>();
this.totalBill = 0;
this.days = days;
}

void addMeal(String meal, double price) {


meals.add(meal);
totalBill += price;
}

void calculateTotalBill() {
totalBill += room.pricePerNight * days;
}

void displayReservation() {
System.out.println("\nReservation Details:");
customer.displayDetails();
room.displayDetails();
System.out.println("Meals Ordered:");
for (String meal : meals) {
System.out.println(" - " + meal);
}
System.out.println("Total Bill: Rs. " + totalBill);
}
}

// Hotel Management System


private RoomNode roomRoot; // BST Root
private Customer[] customers;
private Reservation[] reservations;
private Queue<Customer> waitlist; // Queue for waitlist
private Stack<Reservation> canceledReservations; // Stack for canceled
reservations
private int customerCount = 0, reservationCount = 0;

public Main() {
roomRoot = null;
customers = new Customer[50];
reservations = new Reservation[50];
waitlist = new LinkedList<>();
canceledReservations = new Stack<>();

// Initialize Rooms
addRoom(101, "Single Bed", 2500);
addRoom(102, "Single Bed", 2500);
addRoom(201, "Double Bed", 4000);
addRoom(202, "Double Bed", 4000);
addRoom(301, "Deluxe Room", 6000);
addRoom(302, "Deluxe Room", 6000);
}
void addRoom(int number, String type, double price) {
RoomNode newRoom = new RoomNode(number, type, price);
roomRoot = insertRoom(roomRoot, newRoom);
}

RoomNode insertRoom(RoomNode root, RoomNode newRoom) {


if (root == null) return newRoom;
if (newRoom.roomNumber < root.roomNumber) root.left =
insertRoom(root.left, newRoom);
else root.right = insertRoom(root.right, newRoom);
return root;
}

void viewAvailableRooms() {
System.out.println("\nAvailable Rooms:");
inOrderRoomTraversal(roomRoot);
}

void inOrderRoomTraversal(RoomNode root) {


if (root != null) {
inOrderRoomTraversal(root.left);
if (root.isAvailable && !root.isUnderMaintenance)
root.displayDetails();
inOrderRoomTraversal(root.right);
}
}

void reserveRoom() {
Scanner sc = new Scanner(System.in);
viewAvailableRooms();

System.out.print("Enter Room Number to Reserve: ");


int roomNumber = sc.nextInt();

RoomNode room = findRoom(roomRoot, roomNumber);


if (room == null || !room.isAvailable || room.isUnderMaintenance) {
System.out.println("Room not available! Adding customer to
waitlist.");
sc.nextLine(); // Consume leftover newline
System.out.print("Enter Customer Name: ");
String name = sc.nextLine();
System.out.print("Enter Phone: ");
String phone = sc.nextLine();
System.out.print("Enter Email: ");
String email = sc.nextLine();
waitlist.add(new Customer(name, phone, email, roomNumber));
System.out.println("Customer added to waitlist.");
return;
}

sc.nextLine(); // Consume leftover newline


System.out.print("Enter Customer Name: ");
String name = sc.nextLine();
System.out.print("Enter Phone: ");
String phone = sc.nextLine();
System.out.print("Enter Email: ");
String email = sc.nextLine();
System.out.print("Number of Days: ");
int days = sc.nextInt();

Customer customer = new Customer(name, phone, email, roomNumber);


customers[customerCount++] = customer;

Reservation reservation = new Reservation(customer, room, days);


reservation.calculateTotalBill();
reservations[reservationCount++] = reservation;

room.isAvailable = false;

System.out.println("Reservation successful! Total Bill: Rs. " +


reservation.totalBill);
}

RoomNode findRoom(RoomNode root, int roomNumber) {


if (root == null || root.roomNumber == roomNumber) return root;
if (roomNumber < root.roomNumber) return findRoom(root.left,
roomNumber);
return findRoom(root.right, roomNumber);
}

void cancelReservation() {
Scanner sc = new Scanner(System.in);

System.out.print("Enter Room Number for Check-Out: ");


int roomNumber = sc.nextInt();

for (int i = 0; i < reservationCount; i++) {


if (reservations[i] != null && reservations[i].room.roomNumber
== roomNumber) {
Reservation reservation = reservations[i];
System.out.println("\nGenerating Bill for Customer:");
reservation.displayReservation();

reservation.room.isAvailable = true;
canceledReservations.push(reservation);

if (!waitlist.isEmpty()) {
Customer customer = waitlist.poll();
Reservation newReservation = new Reservation(customer,
reservation.room, 1);
reservations[reservationCount++] = newReservation;
reservation.room.isAvailable = false;
System.out.println("\nCustomer " + customer.name +
" from waitlist is now reserved in Room " +
roomNumber + ".");
}

reservations[i] = null;
System.out.println("Check-Out Complete!");
return;
}
}
System.out.println("No reservation found for Room " + roomNumber +
".");
}

void undoLastCancellation() {
if (canceledReservations.isEmpty()) {
System.out.println("No cancellations to undo.");
return;
}
Reservation lastCancelled = canceledReservations.pop();
lastCancelled.room.isAvailable = false;
reservations[reservationCount++] = lastCancelled;
System.out.println("Last cancellation undone for Room " +
lastCancelled.room.roomNumber + ".");
}
void manageMeals() {
Scanner sc = new Scanner(System.in);

System.out.print("Enter Room Number for Meal Order: ");


int roomNumber = sc.nextInt();

boolean reservationFound = false;


for (Reservation reservation : reservations) {
if (reservation != null && reservation.room.roomNumber ==
roomNumber) {
reservationFound = true;
sc.nextLine(); // Consume leftover newline
System.out.print("Enter Meal Name: ");
String meal = sc.nextLine();
System.out.print("Enter Meal Price: ");
double price = sc.nextDouble();

reservation.addMeal(meal, price);
System.out.println("Meal added successfully!");
break;
}
}

if (!reservationFound) {
System.out.println("Reservation not found for Room " +
roomNumber + ".");
}
}

void start() {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("\nHotel Management System");
System.out.println("1. View Available Rooms");
System.out.println("2. Reserve Room");
System.out.println("3. View Waitlist");
System.out.println("4. Check-Out");
System.out.println("5. Undo Last Cancellation");
System.out.println("6. Manage Meal");
System.out.println("7. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();

switch (choice) {
case 1 -> viewAvailableRooms();
case 2 -> reserveRoom();
case 3 -> {
System.out.println("\nWaitlist:");
if (waitlist.isEmpty()) System.out.println("The
waitlist is empty.");
else waitlist.forEach(customer -> System.out.println("-
" + customer.name));
}
case 4 -> cancelReservation();
case 5 -> undoLastCancellation();
case 6 -> manageMeals();
case 7 -> System.out.println("Exiting...");
default -> System.out.println("Invalid choice!");
}
} while (choice != 6);
}

public static void main(String[] args) {


Main system = new Main();
system.start();
}
}

You might also like