Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA use For this assignment you will write several classes to simulate an online travel agency. Note that for this assignment to be feasible in

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

JAVA use

For this assignment you will write several classes to simulate an online travel agency. Note that for this assignment to be feasible in two weeks, a lot of simplifications have been made. For instance, we are completely ignoring time throughout the assignment. Make sure to follow the instructions below very closely. Note that in addition to the required methods, you are free to add as many other private methods as you want (no other additional method is allowed). You are not allowed to add any additional fields (whether they would be private or public) unless it is stated otherwise. Finally, whenever you are required to compare two strings you can ignore case of the characters. (12 points) Write a class Airport. An airport has the following private fields: An int indicating the x-coordinate of the airport on a world map with a scale to 1 km. An int indicating the y-coordinate of the airport on a world map with a scale to 1 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 (x and 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 (x1, y) and (22, y2), the distance can be computed with the following formula: distance = V(21 22)2 + (y1 - y2)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. 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 reserve Room 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 Illegal ArgumentException 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. [5 points) Write an abstract class Reservation which has the following private field: A String name The class must also have the following public methods: A constructor that takes a String as input indicating the name of the client on the reservation and uses it to initialize the corresponding field. A final reservationName method to retrieve the name on this reservation. An abstract method getCost which takes no input and returns an int. This method should be abstract (thus, not implemented) because how to determine the cost depends on the type of reservation. An abstract method equals which takes an Object as an input and returns a boolean. This method should be abstract as well, since depending on the type of reservation different conditions should be met in order for two reservations to be considered equal. [25 points) All of the followings must be subclasses of Reservation: Write a class Flight Reservation derived from the Reservation class. This class has the following private fields: - An Airport indicating the place of departure. - An Airport indicating the place of arrival. The class has also the following public methods: - A constructor that takes as input a String with the name on the reservation, and two Airports indicating the place of departure and arrival respectively. The constructor uses the inputs to create a Reservation and initialize the corresponding fields. Throw an IllegalArgumentException if the two input airports are the same. Ignore the fact that you did not overrode the equals method in the Airport class. - A get Cost method that takes no input and returns the cost of the reservation an int) in cents. The cost is computed adding together the fuels cost, the aiports fees, and $53.75 (which include costs related to the plane plus taxes). You can assume that 1: * Planes pay $1.24 per gallon of fuel. * Planes can fly 167.52 kilometer per gallon of fuel. The cost should be rounded up to the nearest cent. For example, if after the computation above you obtain a flight cost of 103568.21187 cents, the method should return 103569 cents instead. You may assume that the cost of all reservations fits within an int and therefore doesn't cause overflow. - An equals method which takes as input an Object and return true if input matches this in type, name, and airports. Otherwise the method returns false. You can ignore the fact that you did not overrode the equals method in the Airport class. Write a class HotelReservation derived from the Reservation class. This class has the following private fields: - An Hotel indicating where to make the reservation. A String indicating the type of room to reserve. - An int indicating the number of nights to be spent in the hotel. - An int indicating the price (in cents) for one night in a room of the specified type in the specified hotel. The class has also the following public methods: - A constructor that takes as input a String with the name on the reservation, a Hotel, a String with the room type, and an int indicating the number of nights. The constructor uses the inputs to create a Reservation and initialize the corre- sponding fields. The constructor should also make sure to reserve a room of the correct type in the specified hotel. If such reservation is not possible, then an Illegal ArgumentException should be raised. - A getNumOf Nights method to retrieve the number of night on the reservation. - A get Cost method that takes no input and returns the cost of the reservation (an int) in cents. The cost represents the price to pay for the specified type of room given the number of nights indicated in the reservation. An equals method which takes as input an Object and return true if input matches this in type, name, hotel, room type, number of nights, and total cost. Otherwise the method returns false. Once again, you can ignore the fact that you did not overrode the equals method in the Hotel class. Write a class BnBReservation derived from the HotelReservation class. This class has no fields, but it has the following public methods: - A constructor that takes as input a String with the name on the reservation, a Hotel, a String with the room type, and an int indicating the number of nights. The constructor uses the inputs to create an HotelReservation. - A get Cost method that takes no input and returns the cost of the reservation (an int) in cents. Since this reservation includes breakfast, to the cost of reserving the room in the hotel you should add $10 per night. (18 points) Write a class Basket representing a list of reservations. Note that the instructions on how to implement this class are not always very specific. This is intentional, since your assignment will not be tested on the missing details of the implementation. Note though, that your choices will make a difference in terms of how efficient your code will be. We will not be deducting point for inefficient code in Assignment 1. Note once again that, you are NOT allowed to import any other class (including ArrayList or LinkedList). The class has (at least) the following private field: An array of Reservations. The class must also have the following public methods: A constructor that takes no inputs and initialize the field with an array with no reservations A getProducts method which takes no inputs and returns a shallow copy of the array of Reservations of the basket. This array should contain all the reservations in the basket in the same order in which they were added. An add method which takes as input a Reservation. The method adds the reservation at the end of the list of reservation of the basket and returns how many reservations are now there. A remove method which takes as input a Reservation and returns a boolean. The method removes the first occurrence of the specified element from the array of reser- vation of the basket. If no such reservation exists, then the method returns false, otherwise, after removing it, the method returns true. Note that this method removes a reservation from the list if and only if such reservation is equal to the in- put received. For example, two flight reservations from Montreal to Vancouver are not considered equal if they were created under two different names. After the reservation has been removed from the array, the subsequent elements should be shifted down by one position, leaving no unutilized slots in the middle array. A clear method which takes no inputs, returns no values, and empties the array of reservations of the basket. A getNumOfReservations method that takes no inputs and returns the number of reser- vations in the basket. A getTotalCost method that takes no inputs and returns the cost (in cents) of all the reservations in the basket

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions