0% found this document useful (1 vote)
404 views4 pages

WEB222-Assignment 1

The document provides instructions for Assignment 1 which involves creating a flight reservation application using JavaScript. Students are told to create an array of flight objects with details like carrier, flight number, cities, and seats. They must also create functions to calculate flight prices, search flights by city, display all flights, and reserve seats on a given flight. The assignment then lists steps to perform like displaying flights, searching for flights from cities, updating a flight, reserving seats, and displaying the updated flight list.

Uploaded by

Jimmy Cyrus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
404 views4 pages

WEB222-Assignment 1

The document provides instructions for Assignment 1 which involves creating a flight reservation application using JavaScript. Students are told to create an array of flight objects with details like carrier, flight number, cities, and seats. They must also create functions to calculate flight prices, search flights by city, display all flights, and reserve seats on a given flight. The assignment then lists steps to perform like displaying flights, searching for flights from cities, updating a flight, reserving seats, and displaying the updated flight list.

Uploaded by

Jimmy Cyrus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1

Assignment 1
Instructions:
● Your assessment will be tested using Visual Studio Code. It is your responsibility to ensure
the app runs properly in the same environment.

● In addition to implementing the required functionality, learners are required to use the
coding conventions demonstrated in class (let & const, arrow functions, etc), clear
organization of code, clarity of variable naming, etc. These factors are included as part of
the assessment’s grading criteria. Comments for code snippets are recommended but not
required.

● You are not permitted to use Javascript’s higher order array functions, such as map(),
filter(), forEach(), find(), closest(), etc.

Submission Checklist:
❏ Create a Javascript file containing your assessment solution. Your file must be named:
a1_studentname_studentid.js. Replace studentname and studentid with your name and id.

At the top of your js file, add the following declaration. FIll in the blanks with your student
name, id, and date.

/*********************************************************************************
* WEB222 – Assignment 1
* I declare that this assignment is my own work in accordance with college Academic Policy.
* No part of this assignment has been copied manually or electronically from any other source
* (including web sites) or distributed to other students.
*
* Name: ______________________ Student ID: ______________ Date: ________________
*
********************************************************************************/

In the assessment dropbox, submit your Javascript file

Academic Integrity
● You are to adhere to the college’s Academic Integrity Policy.
https://www.senecacollege.ca/about/policies/academic-integrity-policy.html

● Reposting some or all of this assessment to any website (CourseHero.com, StackOverflow,


etc) constitutes academic dishonesty. Your account will be reported to the website(s) as
violating the website’s Terms of Service and an academic integrity report will be filed with
the college.

● Learners are reminded that using full or partial solutions found on the Internet / other
people is not permitted

○ Distributing “help” or “source code” or “reference” to other learners is not okay


○ Receiving “help” or “source code” or “reference” from others is not okay

Page 1 of 4
2

Problem Description:

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 AA281 DFW ICN 6835.70 miles 10


Airlines

Air Canada AC306 YVR YUL 2291.00 miles 3

Southwest WN3855 PHX STL 1261.38 miles 8


Airlines

Delta Airlines DAL795 PHX MAD 5607.15 miles 1

2. Create the following functions

● calculateFlightPrice(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)

● searchFlights(city, listOfFlights): 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.

● showAllFlights(listOfFlights): 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.

● reserveSeats(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.

Page 2 of 4
3
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

Page 3 of 4
4
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

Page 4 of 4

You might also like