Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a simple Hotel program. We will have two classes, a Hotel class represen

ID: 3540254 • Letter: D

Question

Develop a simple Hotel program. We will have two classes, a Hotel class representing an individual hotel and a Room class. The Hotel class will contain several Room objects and will have several operations. We will also have a driver program to test the Hotel class.

Build a Hotel class that will store information about a Hotel. It will include a name and location. It should also include an Array of instances of class Room to hold information about each room. It will also have a int called occupiedCnt that keeps track of how many rooms in the hotel are occupied. You must use an Array, you cannot use an ArrayList. Set the Array to hold 10 Room objects.

Build a HotelTest class to test your application. Your test class should not require any interaction with the user. It should verify the correct operation of the constructor and all public methods in the Hotel class. Create at least 5 rooms.

Specific Requirements for the Hotel Class:

The Hotel will have an addRoom method that will create each room with the required information: room number, bed type, smoking/non-smoking, and the room rate. Create at least 5 rooms with different characteristics. Each room will also have a boolean field called occupied attribute that will be set to false when the room is created. Don't forget to increment the numOfRooms instance variable. Example values for the rooms are:

101 queen s 100
102 king n 110
103 king n 88
104 twin s 100
105 queen n 99

Hotel

theRooms: Array Room[]
name: String
location: String
occupiedCnt: int

numOfRooms: int

Hotel()

Hotel(String,String)
isFull() : boolean

isEmpty() : boolean
addRoom(int,String,char,double)
addReservation(String,char,String)

cancelReservation(String)
findReservation(String): int

printReservationList()

getDailySales() : double
occupancyPercentage() : double

toString():String

Access and mutator methods for name and location.

isEmpty() %u2013 returns a boolean that is true if all the rooms in the hotel are unoccupied.

When the cancelReservation() method executes, the hotel will search for the name of the visitor in each room. If it is found, the occupied attribute will be set to false. In either case a message will state whether or not the reservation was cancelled. This method calls the private utility method findReservation()to scan the list of rooms looking for a guest by name. It will return the index of the room in the Array of rooms or NOT_FOUND if the room is not found, which will be declared as:

private static final int NOT_FOUND = -1;

printReservationList() will scan through all the rooms and display all details for only those rooms that are occupied. For example:

Room Number: 102
Occupant name: Pinto
Smoking room: n
Bed Type: king
Rate: 110.0

Room Number: 103
Occupant name: Wilson
Smoking room: n
Bed Type: king
Rate: 88.0

occupancyPercentage() will divide occupiedCnt by the total number of rooms to provide an occupancy percentage.

Hotel Name : Beach Marriot
Number of Rooms : 5
Number of Occupied Rooms : 1


Room Details are:


Room

roomNum: int
bedType: String
rate: double
occupantName: String
smoking: char
occupied: boolean

Room()

Room(int,String,char,double)
getBedType(): String
getSmoking(): char       
getRoomNum(): int

getRoomRate(): double

getOccupant(): String
setOccupied(boolean)
setOccupant(String)

setRoomNum(int)

setBedType(String)

setRate(double)

setSmoking(char)

isOccupied(): boolean
toString(): String

isOccupied() method returns true if the room is occupied, false otherwise.

Several accessor and mutator methods for the Room class.

Hotel

theRooms: Array Room[]
name: String
location: String
occupiedCnt: int

numOfRooms: int

Hotel()

Hotel(String,String)
isFull() : boolean

isEmpty() : boolean
addRoom(int,String,char,double)
addReservation(String,char,String)

cancelReservation(String)
findReservation(String): int

printReservationList()

getDailySales() : double
occupancyPercentage() : double

toString():String

Access and mutator methods for name and location.

Explanation / Answer

import java.util.Scanner;

public class Hotel {
public static void main(String[]args) {
int floors, occupiedRooms, totalRooms;

Scanner input = new Scanner(System.in);

//Obtain the number of floors
System.out.print("How many floors are present: ");
floors = input.nextInt();

//loop once for each floor
for(int i = 1; i <= floors; i++) {
System.out.print("Level " + i + ": How many rooms are there: ");
int totalRoomsOnLevel = input.nextInt();
System.out.print("Level " + i + ":How many are occupied: ");
int occupiedRoomsOnLevel = input.nextInt();
System.out.println(); //blank line for appearance
totalRooms += totalRoomsOnLevel;
occupiedRooms += occupiedRoomsOnLevel;
}

System.out.println();
System.out.println("Total hotel rooms: " + totalRooms);
int vacantRooms = totalRooms - occupiedRooms;
System.out.println("Total vacant rooms: " + vacantRooms);

double occupancyRate = (double)occupiedRooms / totalRooms;
System.out.println("Occupancy rate: " + occupancyRate);
}
}