0% found this document useful (0 votes)
2 views

Code

The document contains a Java program for a simple hotel management system that allows users to book rooms and check out. It features options for different room types and payment methods, along with basic validation for user inputs. The program maintains a record of booked rooms and associated guest details, enabling checkouts and room availability management.

Uploaded by

Jatin shah
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Code

The document contains a Java program for a simple hotel management system that allows users to book rooms and check out. It features options for different room types and payment methods, along with basic validation for user inputs. The program maintains a record of booked rooms and associated guest details, enabling checkouts and room availability management.

Uploaded by

Jatin shah
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

public class HotelManagement {


static String[] rooms = new String[5]; // Assuming 5 rooms for simplicity
static double[] roomPrices = {1000.0, 2000.0, 2500.0, 3500.0}; // Prices for
different room types
static double[] roomPayments = new double[5]; // Stores payment amounts for
each room

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
int choice;

do {
System.out.println("\n--- Hotel Management System ---");
System.out.println("1. Book a Room");
System.out.println("2. Check Out");
System.out.println("3. Exit");
System.out.print("Enter your choice (1-3): ");
choice = sc.nextInt();
sc.nextLine(); // Consume the newline character

switch (choice) {
case 1:
bookRoom(sc);
break;
case 2:
checkout(sc);
break;
case 3:
System.out.println("Thank you for using the Hotel Management
System. Goodbye!");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 3);

sc.close();
}

public static void bookRoom(Scanner sc) {


System.out.println("\n--- Room Options ---");
System.out.println("1. Single Bed (Non-A/C) - ₹1,000");
System.out.println("2. Double Bed (Non-A/C) - ₹2,000");
System.out.println("3. Single Bed (A/C) - ₹2,500");
System.out.println("4. Double Bed (A/C) - ₹3,500");
System.out.print("Select a room option (1-4): ");
int roomOption = sc.nextInt();
sc.nextLine(); // Consume the newline character

if (roomOption < 1 || roomOption > 4) {


System.out.println("Invalid room option. Booking canceled.");
return;
}

System.out.print("Enter your desired room number (1-5): ");


int roomNumber = sc.nextInt();
sc.nextLine(); // Consume the newline character
if (roomNumber < 1 || roomNumber > 5) {
System.out.println("Invalid room number. Booking canceled.");
return;
} else if (rooms[roomNumber - 1] != null) {
System.out.println("Room " + roomNumber + " is already booked. Please
choose another room.");
return;
}

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


String name = sc.nextLine();
System.out.print("Enter your phone number: ");
String phone = sc.nextLine();
System.out.print("Enter your email address: ");
String email = sc.nextLine();
System.out.print("Enter your Aadhaar number: ");
String aadhaar = sc.nextLine();
System.out.print("Enter your PAN number: ");
String pan = sc.nextLine();

System.out.println("\n--- Payment Options ---");


System.out.println("1. Cash");
System.out.println("2. UPI");
System.out.print("Select a payment option (1-2): ");
int paymentOption = sc.nextInt();
sc.nextLine(); // Consume the newline character

String paymentDetails;
if (paymentOption == 1) {
paymentDetails = "Paid via Cash";
} else if (paymentOption == 2) {
System.out.print("Enter your UPI ID: ");
String upiId = sc.nextLine();
paymentDetails = "Paid via UPI (ID: " + upiId + ")";
} else {
System.out.println("Invalid payment option. Booking canceled.");
return;
}

double amountPaid = roomPrices[roomOption - 1];


roomPayments[roomNumber - 1] = amountPaid;
rooms[roomNumber - 1] = "Name: " + name + ", Phone: " + phone + ", Email: "
+ email + ", Aadhaar: " + aadhaar +
", PAN: " + pan + ", Payment: " + paymentDetails;

System.out.println("Room " + roomNumber + " booked successfully for " +


name + ". Amount paid: ₹" + amountPaid);
}

public static void checkout(Scanner sc) {


System.out.print("\nEnter room number to check out (1-5): ");
int roomNumber = sc.nextInt();
sc.nextLine(); // Consume the newline character

if (roomNumber < 1 || roomNumber > 5) {


System.out.println("Invalid room number. Please try again.");
} else if (rooms[roomNumber - 1] == null) {
System.out.println("Room " + roomNumber + " is already vacant.");
} else {
System.out.println("\n--- Checkout Details ---");
System.out.println("Room Number: " + roomNumber);
System.out.println("Guest Details:\n" + rooms[roomNumber - 1]);
System.out.println("Amount Paid: ₹" + roomPayments[roomNumber - 1]);
System.out.println("\nThank you for staying with us! We hope to see you
again.");

// Clear the room for future bookings


rooms[roomNumber - 1] = null;
roomPayments[roomNumber - 1] = 0;
System.out.println("Checkout successful.\n");
}
}
}

You might also like