Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java [18 points) Write a class Basket representing a list of reservations. Note that the instructions on how to implement this class are not always

image text in transcribedimage text in transcribedimage text in transcribedjava

[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 get NumOf Reservations 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. (16 points) Write a class Customer which has the following private fields: - A String name An int representing the balance (in cents) of the customer - A Basket containing the reservations the customer would like to make. The class must also have the following public methods: - A constructor that takes as input a String indicating the name of the customer, and an int representing their initial balance. The constructor uses its inputs and creates an empty Basket to initialize the corresponding fields. - A get Name and a getBalance method which return the name and balance in cents) of the customer respectively. - A getBasket method which returns the reference to the basket of the customer no copy of the basket is needed). An addFunds method which takes an int as input representing the amount of cents to be added to the balance of the customer. If the input received is negative, the method should throw an Illegal ArgumentException with an appropriate message. Otherwise, the method will simply update the balance and return the new balance in cents. An addToBasket method which takes a Reservation as input and adds it to the basket of the customer if the name on the reservation matches the name of the customer. If the method is successful it should return the number of reserva- tions in the basket of this customer. Otherwise, the method should throw an Illegal ArgumentException. An addToBasket method which takes a Hotel, a String representing a room type, an int representing the number of nights, and a boolean representing whether or not the customer wants breakfast to be included. The method adds the corresponding reservation to the basket of the customer and returns the number of reservations that are now in the basket of this customer. An addToBasket method which takes two Airports as input. The method adds the corresponding reservation to the basket of the customer and returns the number of reservations that are now in their basket, whether or not the flight reservation was created successfully. - A removeFromBasket method which takes a Reservation as input and removes it from the basket of the customer. The method returns a boolean indicating whether of not the operation was successful. - A checkOut method which takes no input. If the customer's balance is not enough to cover the total cost of their basket, then the method throws an IllegalStateException. Otherwise, the customer is charged the total cost of the basket, the basket is cleared, and balance left is returned

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions