Question
You were hired by a local travel agency to build an application that manages flight reservations. Using Javascript, you are to create a console based
You were hired by a local travel agency to build an application that manages flight reservations. Using Javascript, you are to create a console based application per the specifications below.
1. Create an array of flights. Each flight in the array must be represented as an object literal. Every flight has a carrier, flight number, departure city, arrival city, flight distance, and total number of available seats. You must include the following flights in your array.
Carrier Flight Number Departure City Arrival City Distance Available Seats American Airlines AA281 DFW ICN 6835.70 miles 10 Air Canada AC306 YVR YUL 2291.00 miles 3 Southwest Airlines WN3855 PHX STL 1261.38 miles 8 Delta Airlines DAL795 PHX MAD 5607.15 miles 1
2. Create the following functions
● calculate Flight Price(flight): This function accepts a single flight object and returns the total cost of the flight as a number. The flight price is calculated as follows: $100 + (Flight Distance * $0.12)
● search Flights(city, list Of Flights): This function accepts a city name and an array of flight objects. Using a loop, the function should search the array of flights and return the total number of flights departing the specified city. If there are no flights departing from the specified city, the function should return 0.
● show All Flights(list Of Flights): The function accepts an array of flights and displays the flight number, departure city, and arrival city for each flight, as follows:
Flight AA281, departing DFW and arriving ICN. Seats Remaining: 10
Flight AC306, departing YVR and arriving YUL. Seats Remaining: 3
Flight WN3855, departing PHX and arriving STL. Seats Remaining: 8
Flight DAL795, departing PHX and arriving MAD. Seats Remaining: 1
Note that the function must work for any array of flight objects, of any size.
● reserve Seats(flightNumber, numSeats, listOfFlights): Function accepts a flight number (string), number of seats to reserve (number) and list of available flights (array of flight objects). Using a loop, the function should search the list of flights for a flight that matches the provided flight number and return true or false based on whether the reservation was successful.
Specifically, if the function is able to find a matching flight, the function should attempt to to reserve the number of available seats on the flight by the specified amount. If there is an insufficient number of seats available, then the operation should fail and the function should return false. If there is a sufficient number of seats, the function should reduce the amount of available seats by the requested amount. The function should then return true.
If the function cannot find a flight matching the specified flightNumber, the function should return false.
3. After creating these functions, write the code to perform the following operations. Wherepossible, you must use the calculateFlightPrice, searchFlights, showAllFlights, and reserveSeats functions.
1. Output the list of available flights
2. Search for flights departing DFW. If yes, display the number of flights found. If no, output “No flights found”.
3. Search for flights departing PHX. If flights found, display the number of flights found. If no, output “No flights found”.
4. Retrieve flight #AC306 from the list of flights. Using the AC306 object:
a. Calculate the price of the AC306 flight
b. Update the flight’s arrival city to PTY
c. Update the flight’s distance to 4494.00
d. Calculate the new price of the AC306 flight
e. To the console, display:
i. The old price of AC306
ii. The new price of AC306
iii. The percentage difference in prices, to 2 decimal points
(HINT: Use the toFixed() function)
5. Reserve 10 seats on WN3855. If successful, output a confirmation message. Otherwise, output a failure message.
6. Reserve 5 seats on AA281. If successful, output a confirmation. Otherwise, output a failure message.
7. Output a list of available flights.
NOTE: If you have created / implemented everything correctly, the list of available flights will contain:
a. the updated information for AC306
b. the updated seat counts, if any, for WN3855 and AA281
Sample output
When writing your code, please make it obvious what your program is doing. For example, if your program will be searching for a flight, then your output should indicate that the program is searching for something.
See below for an example of what a clear and obvious program output is. Your specific program output may be slightly different depending on the specific requirements listed above.
Note, the coloured & highlighted text is for your reference only. Your output should not have coloured text.
Available Flights:
Flight AA281, departing DFW and arriving ICN. Seats Remaining: 10
Flight AC306, departing YVR and arriving YUL. Seats Remaining: 3
Flight WN3855, departing PHX and arriving STL. Seats Remaining: 8 Flight DAL795, departing PHX and arriving MAD. Seats Remaining: 1
Are there flights leaving PHX today?
There are 2 flights departing PHX
Are there flights leaving YYZ today?
No flights found.
Flight A306 is being updated
The previous price of AC306 is: 374.92
The updated price of AC306 is: 639.28
This is a difference of: 70.51%
Attempting to reserve 10 seats on WN3855: false
Attempting to reserve 5 seats on AA281: true
Available Flights:
Flight AA281, departing DFW and arriving ICN. Seats Remaining: 5
Flight AC306, departing YVR and arriving PTY. Seats Remaining: 3
Flight WN3855, departing PHX and arriving STL. Seats Remaining: 8
Flight DAL795, departing PHX and arriving MAD. Seats Remaining: 1
Step by Step Solution
3.41 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
1 Create an array of flights Each flight in the array must be represented as an object literal Every flight has a carrier flight number departure city arrival city flight distance and total number of ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started