Project Solution: Hotel Booking System
☰Fullscreen
Table of Content:
public class Hotel { public static void main(String[] args) { // Sample data String customerName = "Rumman Ansari"; int membershipCode = 2; String roomType = "Deluxe"; int numberOfRooms = 2; int numberOfDays = 5; // Initialize variables int perDayCharge = 0; int deluxeDiscount = 0; int superDeluxeDiscount = 0; int bill = 0; int discount = 0; int amountPayable = 0; // Welcome message System.out.println("\t\tWelcome to Hotel Dream Land"); System.out.println(); System.out.println("Customer Name: " + customerName); System.out.println("Membership Code: " + membershipCode); // Membership discounts switch (membershipCode) { case 1: System.out.println("Dear " + customerName + ", you opted for a Gold Membership."); System.out.println("Here are the Gold membership Seasonal Discount rates:"); System.out.println("Deluxe Room @5% \nSuper Deluxe @10%"); deluxeDiscount = 5; superDeluxeDiscount = 10; break; case 2: System.out.println("Dear " + customerName + ", you opted for a Diamond Membership."); System.out.println("Here are the Diamond membership Seasonal Discount rates:"); System.out.println("Deluxe Room @15% \nSuper Deluxe @20%"); deluxeDiscount = 15; superDeluxeDiscount = 20; break; case 3: System.out.println("Dear " + customerName + ", you opted for a Platinum Membership."); System.out.println("Here are the Platinum membership Seasonal Discount rates:"); System.out.println("Deluxe Room @25% \nSuper Deluxe @30%"); deluxeDiscount = 25; superDeluxeDiscount = 30; break; default: System.out.println("Dear customer, you have chosen a wrong membership type!"); System.out.println("Please enter correct membership code 1, 2, or 3."); System.exit(0); } // Room type and charges if (roomType.equalsIgnoreCase("Deluxe")) { System.out.println("You have chosen Deluxe Rooms."); perDayCharge = 2500; bill = perDayCharge * numberOfRooms * numberOfDays; discount = bill * deluxeDiscount / 100; amountPayable = bill - discount; } else if (roomType.equalsIgnoreCase("Super Deluxe")) { System.out.println("You have chosen Super Deluxe Rooms."); perDayCharge = 4200; bill = perDayCharge * numberOfRooms * numberOfDays; discount = bill * superDeluxeDiscount / 100; amountPayable = bill - discount; } else { System.out.println("Wrong Room Type"); System.out.println("Please enter correct room code 'Deluxe' or 'Super Deluxe'."); System.exit(0); } // Display the tariff details System.out.println(); System.out.println("\tTariff Detail"); System.out.println(); System.out.println("Tariff Per Day: " + perDayCharge); System.out.println("Number of Rooms: " + numberOfRooms); System.out.println("Number of Days: " + numberOfDays); System.out.println(); System.out.println("Bill Amount: Rs." + bill); System.out.println("Seasonal Discount: Rs." + discount); System.out.println("Net Payable Amount: Rs." + amountPayable); System.out.println(); } }
Explanation of Corrections:
- Program Structure: Ensured the program has a
main
method that serves as the entry point and used sample data for simplicity. - Input Data: Provided sample customer details, membership code, room type, number of rooms, and number of days.
- Membership Discounts:
- Added a switch-case statement to set the discount rates based on the membership code.
- Room Type and Charges:
- Checked the room type and calculated the bill, discount, and payable amount accordingly.
- Printing Statements: Corrected the print statements to ensure they display the correct data and improved formatting.
Now, you can compile and run this program to see the output for the given sample data. You can replace the sample data with actual inputs to generate bills for different customers.
Output
Welcome to Hotel Dream Land Customer Name: Rumman Ansari Membership Code: 2 Dear Rumman Ansari, you opted for a Diamond Membership. Here are the Diamond membership Seasonal Discount rates: Deluxe Room @15% Super Deluxe @20% You have chosen Deluxe Rooms. Tariff Detail Tariff Per Day: 2500 Number of Rooms: 2 Number of Days: 5 Bill Amount: Rs.25000 Seasonal Discount: Rs.3750 Net Payable Amount: Rs.21250