In: Computer Science
Hotel California is a small modern-style hotel located not too far from the Central Bangkok District. Your job is to write a simple piece of software to manage the room occupancy. The hotel has two buildings; each building has four floors; and each floor has a different number of rooms. Building A has five rooms on each floor. Building B has four rooms on each floor. Each room is graded with Standard, Deluxe, and Suite, and the rates per night are $100, $250, and $600 respectively. In both buildings, the rooms on the first and the second floors are Standard; the rooms on the third floor are Deluxe; and the rooms on the fourth floor are Suite.
Write a program that allows the hotel front desk to reserve a room for its customers. When a customer reserves a room, he needs to provide his name (first name and last name), his phone number and the room grade. The system must check for the availability of that room grade. If the preferred room grade is available, the reservation number will be generated and the room number will be assigned to that reservation. If there are no rooms of that grade available, a proper message must be shown.
Note that the hotel policy allows only 1 room with
1-night stay per booking. If the customer wants to book more than
one rooms, he needs to make more reservations. The hotel allows the
room to be booked only one day in advance. Hence, the system will
only have the booking for tomorrow's check-in.
The front desk should also be able to record the payment
for a reservation during the customer's check-out process (given a
reservation number, the customer's name or the customer's phone
number). If the customer has more than one reservations made on
that day, the list of reservations must be shown so the front desk
can apply the payment to such a reservation. In order to keep track
of the hotel's income, the staff should be able to print the sales
reports for each building (grouped by the room
grades).
Use java to Design and implement the system for Hotel California. Comment on methods and functions to explain the logic of your code
:: Solution ::
import java.util.ArrayList;
import java.util.Scanner;
class Room{
String firstname,lastname,roomgrade;
int phoneNumber;
public Room(String firstName,String lastName, int phone, String
roomGrade ){
this.firstname = firstName;
this.lastname = lastName;
this.phoneNumber = phone;
this.roomgrade = roomGrade;
}
void printDetails(){
System.out.println("Name :" +this.firstname +" " +
this.lastname);
System.out.println("Phone: " + this.phoneNumber);
System.out.println("Room Grade :" + this.roomgrade);
System.out.println("Payment : " + this.payment());
}
int payment(){
if (this.roomgrade == "Suite")
return 600;
else if (this.roomgrade.equals("Delux"))
return 250;
else
return 100;
}
}
public class Main {
public static void main() {
ArrayList<Room> customersA = new
ArrayList<Room>();
ArrayList<Room> customersB = new
ArrayList<Room>();
int enex = 0;
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Enter 1 for entry 0 for exit of customer!
:");
enex = sc.nextInt();
if (enex == 1)
entry(customersA, customersB);
if (enex == 0) {
System.out.println("Enter First Name: ");
String firstname = sc.next();
System.out.println("Enter Last Name: ");
String lastname = sc.next();
System.out.println("ENter Phone number: ");
int phone = sc.nextInt();
exit(firstname, lastname, phone, customersA, customersB);
}
}
}
public static void exit(String firstName, String lastName, int phone, ArrayList<Room> customersA, ArrayList<Room> customersB) {
int Asize = customersA.size();
int Bsize = customersB.size();
for (int i = 0; i < Math.max(Asize, Bsize); i++) {
if (i < Asize)
if (customersA.get(i).firstname.equals(firstName)) {
if (customersA.get(i).lastname.equals(lastName)) {
if (customersA.get(i).phoneNumber == phone) {
customersA.get(i).printDetails();
customersA.remove(customersA.get(i));
}
}
}
if (i < Bsize)
if (customersB.get(i).firstname.equals(firstName)) {
if (customersB.get(i).lastname.equals((lastName))) {
if (customersB.get(i).phoneNumber == phone) {
customersB.get(i).printDetails();
customersB.remove(customersB.get(i));
}
}
}
}
}
public static void entry(ArrayList<Room> customersA, ArrayList<Room> customersB) {
int totalCustomers = 0;
int occupiedStandardA = 0;
int occupiedStandardB = 0;
int occupiedDeluxA = 0;
int occupiedDeluxB = 0;
int occupiedSuiteA = 0;
int occupiedSuiteB = 0;
String firstName = "";
String lastName = "";
int phone = 0;
String roomGrade = "";
Scanner sc = new Scanner(System.in);
char exit = ' ';
while (exit != 'Y' || exit != 'y') {
System.out.println("Enter first Name: ");
firstName = sc.next();
System.out.println("Enter Last Name: ");
lastName = sc.next();
System.out.println("Enter Phone Number: ");
phone = sc.nextInt();
System.out.println("Enter Room Grade(Standard, Delux, Suite):
");
roomGrade = sc.next();
System.out.println("Exit [Y/N]");
exit = sc.next().strip().charAt(0);
if (roomGrade.equals("Standard")) {
if (occupiedStandardA < 10) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedStandardA += 1;
totalCustomers += 1;
customersA.add(customer);
} else if (occupiedStandardB < 8) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedStandardB += 1;
totalCustomers += 1;
customersB.add(customer);
} else
System.out.println("No Standard Rooms Available!!");
} else if (roomGrade.equals("Dulex")) {
if (occupiedDeluxA < 5) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedDeluxA += 1;
totalCustomers += 1;
customersA.add(customer);
} else if (occupiedDeluxB < 4) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedDeluxB += 1;
totalCustomers += 1;
customersB.add(customer);
} else
System.out.println("No Delux Rooms Available!!");
} else if (roomGrade.equals("Suite")) {
if (occupiedSuiteA < 5) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedSuiteA += 1;
totalCustomers += 1;
customersA.add(customer);
} else if (occupiedSuiteB < 4) {
Room customer = new Room(firstName, lastName, phone,
roomGrade);
occupiedSuiteB += 1;
totalCustomers += 1;
customersB.add(customer);
} else
System.out.println("No Suite Available!!");
} else
System.out.println("No Rooms Available!!");
}
}
}