QUESTION

Text
Image


[12 points] Write a class Airport. An airport has the following private fields: - An int indicating the $\mathrm{x}$-coordinate of the airport on a world map with a scale to $1 \mathrm{~km}$. - An int indicating the y-coordinate of the airport on a world map with a scale to $1 \mathrm{~km}$. - An int indicating the airport fees (in cents) associated to this airport. The class must also have the following public methods: - A constructor that takes three int as input indicating the position of the airport on a map ( $\mathrm{x}$ and $\mathrm{y}$ coordinate) and the fees of the airport (in cents) respectively. The constructor uses the inputs to initialize the corresponding fields. - A getFees method to retrieve the fees of the airport. - A static method getDistance which takes as input two airport and returns a integer indicating the distance in kilometer between the two airports. Note that the method should round the distance up (e.g. both 5.9 and 5.2 should become 6). More over, remember that given two points $\left(x_{1}, y_{1}\right)$ and $\left(x_{2}, y_{2}\right)$, the distance can be computed with the following formula: \[ \text { distance }=\sqrt{\left(x_{1}-x_{2}\right)^{2}+\left(y_{1}-y_{2}\right)^{2}} \] [12 points] Write a class Room. An room has the following private fields: - A String indicating the type of the room. - An int indicating the price (in cents) of the room. - A boolean indicating whether or not the room is available. The class must also have the following public methods: - A constructor that takes as input the type of the room and uses it to initialize the fields. Note that there are only 3 type of rooms supported by the program: double, queen, and king. If the input does not match one of these room type, then the constructor should throw an IllegalArgumentException explaining that no room of such type can be created. The price of the room is based on its type as follows: $\$ 90$ for a double, $\$ 110$ for a queen, $\$ 150$ for a king. Remember that the price should be stored in cents. The constructor should set the availability for a new room to be true. 3
- A constructor that takes a Room as input and creates a copy of the input room (i.e. it initialize the fields using the values from the corresponding fields of the input room). - A getType and a getPrice method which return the type and the price of the room respectively. - A changeAvailability method which takes no input and sets the value stored in the availability field to be the opposite of the one currently there. - A static method findAvailableRoom which takes as input an array of Rooms as well as a String indicating a room type. The method should return the first available room in the array of the indicated type. If no such room exists (either because all rooms of said type are occupied, or because no room of such type is in the array), the method returns null. Note that, no changes to any of the rooms in the input array should be made by this method! - A static method makeRoomAvailable which takes as input an array of Rooms as well as a String indicating a room type. The method should make the first unavailable room in the array of the indicated type available again. If successful, the method should return true, otherwise the method should return false.
[12 points] Write a class Hotel. An hotel has the following private fields: - An String indicating the name of the hotel. - An array of Rooms indicating the rooms in the hotel. The class must also have the following public methods: - A constructor that takes a String and an array of Rooms respectively. The constructor uses the inputs to initialize the corresponding fields. Note that the array used to initialize the field representing the rooms should be a deep copy of the input array. - A reserveRoom method which takes as input a String indicating the type of room to reserve. The method changes the availability of the first available room of the specified type in the hotel. If successful, the method returns the price of the room. Otherwise, an IllegalArgumentException should be thrown. - A method cancelRoom which takes as input a String indicating the type of room to cancel. The method makes a room of that type available again. It returns true if it operation was possible, false otherwise.these three questions with java

Public Answer

ZJWRF9 The First Answerer