0% found this document useful (0 votes)
10 views6 pages

Java Hotel Class Development Guide

Jaba script and java ascript

Uploaded by

luckyvishwanth
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)
10 views6 pages

Java Hotel Class Development Guide

Jaba script and java ascript

Uploaded by

luckyvishwanth
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

GA_Coding Question-Java Classes.

1 hr
Program Specifications Write a basic Hotel class to support basic operations
such as booking Reservations and managing Rooms. [Link] is provided
with stubs for the Hotel, Reservation, and Room classes.
Note: This program is designed for incremental development. Complete each
step. Partial credit is given for steps that are partially completed. The main()
method in [Link] includes basic method calls. Add statements in
main() as methods are completed to support development mode testing.
Step 0. Declare private fields
in the Hotel class for:
- Name of the Hotel (string)
- List of the Hotel’s rooms (ArrayList<Room>)
- List of Reservations (ArrayList<Reservation>)
- Total earnings (double)
in the Room class for:
- ID of the Room (string)
- The price per night of the Room (double)
- The guest capacity of the Room (int)
- Available or not (boolean)
in the Reservation class for:
- The name of the customer booking the reservation (string)
- The number of guests included in the reservation (int)
- The number of nights (int)
- The ID of the Room used for the reservation (string)
Complete the given getter and setter methods for the fields of each class so
that fields can be accessed and modified throughout the program.
Step 1 (1 pts). 1) Complete the constructor:
in the Hotel class to:
- Initialize the name of the hotel from a parameter.
- Set the initial list of Reservations and list of Rooms to empty.
- Set the total earnings to 0.
in the Room class to:
- Set the ID, price per night, and guest capacity of the room from
parameters.
- Set available to true initially.
in the Reservation class to:
- Set the booking customer’s name, the number of guests, and the
number of nights from parameters.
- Set the room ID of the Reservation to an empty string.
Step 2 (1 pt). In the Hotel class, complete the addRoom() method. Take a
Room object from the parameter and add it to the list of the Hotel’s Rooms.
Do not add the Room if the ID string attribute of the given Room is already
used by another existing Room in the Hotel (i.e., inputted Room with ID of
‘1234’ should not be added if an existing Room in the Hotel has that ID).
Step 3 (2 pt). In the Hotel class, Complete the bookReservation() method.
Take the Reservation object from the parameter and:
- Find a Room in the Hotel’s list of Rooms that is available and has a
guest capacity that is greater or equal to the number of guests
attributed to the Reservation.
Set that Room to be unavailable (available set to false). Increase the
Hotel’s total earnings by the Room’s price per night times the
Reservation’s number of nights.
Set the Reservation’s room ID attribute to the ID of the Room that is
found and then add the Reservation to the Hotel’s list of Reservations.
- If no Room is found (i.e no Room in the Hotel is available or no Room
has a guest capacity that can satisfy the need of the Reservation) then
do not add the Reservation or the earnings to the Hotel.
Step 4 (1 pt). In the Hotel class, complete the checkOut() method. Remove the
Reservation given in the parameter from the Hotel’s Reservation list and set
the Hotel’s Room with the room ID included in the Reservation to available
(true).
Step 5 (5 pts). Add a rating (double) attribute to the Room class. Initialize it in
the Room’s constructor to be 0.
Add an average-rating (double) attribute to the Hotel class. Initialize it in the
Hotel’s constructor to be 0.

In the Hotel class, complete the calculateOverallRating() method to iterate


over the Rooms of the Hotel, obtain each Room’s rating and use that to
calculate the overall average rating of the Hotel. (i.e. if the hotel has rooms
with rating=2.0, rating=4.0, and rating = 3.0, then the average rating of the
hotel would be 3.0)
Modify the Hotel’s checkOut() method to take an additional customer-rating
(double) parameter and set the Room’s rating attribute to this value. (The
appropriate Room can be found using the room ID field of the Reservation
passed to this method)
Modify the Hotel’s bookReservation() method to consider all the Rooms in the
Hotel that are applicable to the Reservation (i.e. Rooms that are available and
have the needed guest capacity), but pick the Room with the highest rating
amongst those.

Sketch Code [Link] ( no need to change)

public class LabProgram {


public static void main(String[] args) {
Hotel hotel1 = new Hotel("My Hotel");
Room room1 = new Room("12345", 75.0, 3);
Room room2 = new Room("47852", 80.0, 2);

Reservation reservation1 = new Reservation("John Smith", 3, 7);

// Test basic operations


[Link](room1);
[Link](room2);
[Link](reservation1);
[Link](reservation1);
[Link]("Hotel: " + [Link]());
[Link]("Hotal Earnings: " + [Link]());
[Link]("Rooms: ");
for(Room room : [Link]()){
[Link]("Room ID: "+[Link]()+" Capacity: "+[Link]()+"
Rating: "+[Link]());
}

// Add statements as methods are completed to support development mode testing

}
}
Sketch Code [Link]

import [Link];

public class Hotel{


private String hotelName;
//... add the rest

public Hotel(String hotelName){


// complete the Hotel constructor
}

public void addRoom(Room room){


// complete the method
}

public void bookReservation(Reservation reservation){


// complete the method
}

public void checkOut(Reservation reservation){


// complete the method
}

public void updateRatings(){


// complete the method
}

// complete the getter methods for Hotel


public String getHotelName(){
return "";
}

public ArrayList<Room> getRooms(){


return "";
}

public double getTotalEarnings(){


return "";
}
}

class Room{
private String roomID;
//... add the rest

public Room(String roomID, double pricePerNight, int guestCapacity){


// complete the Room constructor
}

// complete the following getter and setters for Room


public String getRoomID(){
return "";
}

public double getPricePerNight(){


return -1;
}

public int getGuestCapacity(){


return -1;
}

public boolean getAvailability(){


return false;
}

public double getRating(){


return -1;
}

public void setAvailability(boolean availability){


return;
}

public void setRating(double rating){


return;
}
}

class Reservation{
private String customerName;
//... add the rest

public Reservation(String customerName, int numGuests, int numNights){


// complete the Reservation constructor
}
// complete the following getter and setters for Reservation
public String getCustomerName(){
return "";
}

public int getNumGuests(){


return -1;
}

public int getNumNights(){


return -1;
}

public String getRoomID(){


return "";
}

public void setRoomID(String roomID){


return;
}
}

Common questions

Powered by AI

The program employs object-oriented principles by using encapsulated classes with specific responsibilities. The Hotel class manages Room objects and Reservation objects, maintaining lists of each while providing methods to add Rooms and book Reservations. The relationship is managed through method calls where the Hotel class interacts with Room objects for availability checks and Reservation objects for booking operations, utilizing getters and setters for internal attribute management .

The calculateOverallRating() method enhances the Hotel class by providing a measure of quality based on guest feedback. It iterates over all Rooms to compute the average rating, offering an overview of the hotel's performance. This feature informs potential guests and management about the service quality, which can influence business decisions and customer satisfaction .

The Room class design is relatively flexible due to its encapsulated attributes and methods for accessing and modifying them. However, its current design might limit extension due to direct attribute manipulations. Future changes would benefit from more abstracted interfaces or listeners for attribute changes, allowing for more seamless integration of additional features like dynamic pricing or extended capacity management .

The earnings of a Hotel are calculated by multiplying the price per night of the booked Room by the number of nights in the Reservation. The bookReservation() method updates the Hotel’s total earnings by adding this amount each time a Reservation is successfully made, ensuring that the earnings reflect the cumulative income from all completed bookings .

The availability attribute in the Room class indicates whether the Room is currently available for booking. During the booking process, the bookReservation() method checks this attribute to find available Rooms. Once a Room is booked, its availability is set to false, preventing further bookings until it is checked out and set to true again .

The incremental development approach benefits implementation and testing by allowing developers to focus on completing smaller, manageable segments of the program. This approach facilitates early identification and rectification of errors, verification of fulfillment of specifications, and integration testing of each part. Moreover, it allows for partial credit and iterative enhancements, which are advantageous in structured learning and development environments .

The program ensures Room ratings reflect customer feedback by adding a customer-rating parameter to the checkOut() method. When the method is executed, it updates the Room’s rating using the provided customer rating value, allowing for dynamic adjustments based on guest experiences .

The design ensures unique room identification by using the addRoom() method in the Hotel class, which checks if a Room with the same ID already exists in the hotel's list of Rooms. The method does not add a Room if its ID is already present, thereby ensuring that each Room ID is unique .

Improvements to the checkout mechanism should include validation checks for Reservation integrity before processing. Enhancements may incorporate verifying the presence of the Reservation in the Hotel's system and using exception handling for cases where a Room ID does not exist or is not associated with any active Reservation. Adding logging for unsuccessful checkout attempts and audit trails would reinforce robustness and error diagnosis .

The effectiveness of the Room selection method during booking is enhanced by prioritizing available Rooms based on their ratings. When multiple Rooms meet the guest capacity requirement, the bookReservation() method chooses the Room with the highest rating, optimizing for customer satisfaction and ensuring that higher-rated Rooms are prioritized, which can enhance service quality perception .

You might also like