Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code in java 1. In this question, you will implement two methods for a class Hotel that is part of a hotel reservation system. The

code in java

image text in transcribedimage text in transcribedimage text in transcribed

1. In this question, you will implement two methods for a class Hotel that is part of a hotel reservation system. The Hotel Class uses the Reservation class shown below. A Reservation is for the person and room number specified when the Reservation is constructed. public class Reservation { public Reservation(String guest Name, int roomNumber) { /* implementation not shown */ } public int getRoomNumber() { /* implementation not shown */ } // private data and other methods not shown An incomplete declaration for the Hotel class is shown below. Each hotel in the hotel reservation system has rooms numbered 0, 1, 2, ..., up to the last room number in the hotel. For example, a hotel with 100 rooms would have rooms numbered 0, 1, 2, ..., 99. public class Hotel private Reservation[] rooms; 1/ each element corresponds to a room in the hotel; // if rooms[index] is null, the room is empty; 11 otherwise, it contains a reference to the Reservation // for that room, such that 1/ rooms (index).getRoomNumber() returns index private ArrayList waitList; 1/ contains names of guests who have not yet been // assigned a room because all rooms are full // if there are any empty rooms (rooms with no reservation), 1/ then create a reservation for an empty room for the 1/ specified guest and return the new Reservation; 11 otherwise, add the guest to the end of waitList // and return null public Reservation request Room (String guestName) { /* to be implemented in part (a) */ } // release the room associated with parameter res, effectively // canceling the reservation; 11 if any names are stored in waitList, remove the first name // and create a Reservation for this person in the room // reserved by res; return that new Reservation; // if waitList is empty, mark the room specified by res as empty and // return null // precondition: res is a valid Reservation for some room in this hotel public Reservation cancelAndreassign (Reservation res) { /* to be implemented in part (b) */ } // constructors and other methods not shown (a) Write the Hotel method request Room. Method request Room attempts to reserve a room in the hotel for a given guest. If there are any empty rooms in the hotel, one of them will be assigned to the named guest and the newly created reservation is returned. If there are no empty rooms, the guest is added to the end of the waiting list and null is returned. Complete method request Room below. // if there are any empty rooms (rooms with no reservation), // then create a reservation for an empty room for the // specified guest and return the new Reservation; // otherwise, add the guest to the end of waitList // and return null public Reservation request Room (String guestName) (b) Write the Hotel method cancelAndReassign. Method cancelAndreassign releases a previous reservation. If the waiting list for the hotel contains any names, the vacated room is reassigned to the first person at the beginning of the list. That person is then removed from the waiting list and the newly created reservation is returned. If no one is waiting, the room is marked as empty and null is returned. In writing cancelAndreassign you may call any accessible methods in the Reservation and Hotel classes. Assume that these methods work as specified. Complete method cancelAndreassign below. // release the room associated with parameter res, effectively // canceling the reservation; // if any names are stored in waitList, remove the first name // and create a Reservation for this person in the room // reserved by res; return that new Reservation; // if waitList is empty, mark the room specified by res as empty and // return null // precondition: res is a valid Reservation for some room in this hotel public Reservation cancel Andreassign(Reservation res)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

=+What sanctions are available to employers

Answered: 1 week ago

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago