Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Swift Programming Assignment 1 In this assessment, you will use Swift to implement a console-based application that manages flight reservations

Swift Programming Assignment 1 In this assessment, you will use Swift to implement a console-based application that manages flight reservations

Computer Science

Swift Programming Assignment 1

In this assessment, you will use Swift to implement a console-based application that manages flight reservations.

SUBMISSION CHECKLIST

For your project to be graded, submit a zip file containing your code, named Flights_FirstName_UserName.zip. No 7zip or rar files accepted.

HOW TO CREATE YOUR ZIP FILE

If you are using XCode, use the following procedure to generate your zip

  1. Create a new Command Line Tool project in XCode
  2. Name the project Flights_FirstName_Username (example: Flights_Emily_esmith105):

 

  1. Code your solution
  2. When you are ready to submit, find your XCode project folder,  and zip it

 

 

       6.   Submit the *.zip file to the course dropbox.

If you are not using XCode, generate your zip file as follows:

  1. Create a folder called Flights_YourFirstName_UserName. For example: Flights_Emily_esmith105
  2. Copy your *.swift files to the folder
  3. Zip the folder
  4. Name the folder Flights_YourFirstName_UserName.  For example: Flights_Emily_esmith105.zip
  5. Submit the zip file to the assessment dropbox.

GRADING CRITERIA

Grading is based on functional correctness and the learner’s object oriented design. Besides implementing the required functionality, submissions are also evaluated based on usage of coding conventions demonstrated in class, professional organization of the code, alignment, and clarity of variable/function naming. Comments for code snippets are recommended but not required.

ACADEMIC INTEGRITY

  1. Learners are responsible for familiarizing themselves with the college’s Academic Integrity policies.
  2. This is an individual assessment and collaboration with others (either inside or outside the class) is not permitted.  Collaboration includes: working with others to develop a solution, showing your code to others as a ‘reference’, or requesting others to provide you a ‘reference’.
  3. You are not permitted to search the Internet for full or partial solutions, follow online tutorials/videos/websites that contain similar tasks/activities, or to seek assistance on homework sharing websites.

TASK

You were hired by a local travel agency to build an application that manages flight reservations.

Based on the following class diagram and descriptions, you are to:

  1. Implement the classes, attributes, and functions. For each class, you are responsible for choosing the most appropriate data types and function return types based on the overall application description.  All classes must have appropriate initializers.
  2. After implementing all classes and interfaces, create a Main file per the requirements indicated in the Main.swift section.

Class diagram

 

CanBeDisplayed protocol

This protocol contains a function called display().

Flight Class:

  1. Create a class called Flight that has the following properties
  • Flight Number
  • Departure airport
  • Arrival airport
  • Distance (flight distance between the arrival and departure airports, in miles)
  • Cost
  1. The cost property is a computed property that outputs the total cost of the flight.  The cost of the flight is calculated as follows

Flights over 500 miles:   $1000 + distance * 0.25 / mile

Flights of 500 miles or less:  $200 + distance * 0.5 / mile

  1. The Flight class must conform to the CanBeDisplayed protocol. The display() function must output the flight information, as follows:

Departing DFW, Arriving ICN on Flight #AA281

Reservation Class:

  1. Create a class called Reservation that inherits all the Flight class’ attributes and methods.
  2. In addition to the inherited properties, every Reservation class must have the following properties:
    • Reservation Id (string)
    • Reservation date (string)
  3. The reservation id must be generated at the time the object is initialized (ie: do not use the initializer’s parameters to set the id). The reservation consists of a 5 character string in the format X X X L or X X X X S. X X X X represents a randomly generated numer between 1000-9999, inclusive..  The reservation ID ends in the character “L”  if the flight is more than 500 miles long.  The reservation ID ends in the character “S” if the flight is 500 miles or less.   Examples of reservation id could be  “1234L” or “9218S”
  1. After the value of the reservation id is initialized, it cannot be changed
  2. The Reservation class must override the parent class’ display() function. The Reservation class’ display() function must output the information about the current reservation to the screen. The format of the output should be as follows:

Reservation ID:  1503L

Date of Departure: 2022-04-01

Departing DFW, Arriving ICN on Flight #AA281

Your implementation of the Reservation class display() function must utilize the parent class’ display() function.

Traveller Class:

  1. Create a Traveller class with the following properties:
    • Name    reservationsList (a list of Reservations
    • Passport number            associated with the traveller)
    • Email address    balance
  2. The Traveller class has an initializer that sets the initial values of the customer id, passport number, name, and email address.   Every Traveller object should be initialized with no reservations.
  3. The Traveller’s name cannot be changed after initialization.
  4. The Traveller’s passport number is a 5 digit number between 10000 and 99999, inclusive. All other values are invalid. If a Traveller object is initialized with an invalid passport number, then the object’s passport number should be set to nil.
  5. The Traveller’s balance is a computed property that returns the total cost of the Traveller’s reservations.
  6. The Traveller class contains a  function called makeReservation(reservationDate, flight).  This function accepts a reservation date and flight object. The function uses the reservationDate and flight object to create and add a corresponding Reservation object to the traveller’s list of reservations. Note that reservations can only be created if the Traveller has a valid passport number. If a reservation is successfully created and added to the list of reservations, return true.  Otherwise, the function returns false.
  7. The Traveller class must conform to the CanBeDisplayed protocol. The display() function must output information about the Traveller’s name, email, passport number validity, and a list of their reservations (if any).
    • If the Traveller has a valid passport, then output “Yes'' for the passport number validity. Otherwise, output “No”.  Example:

Name:  William Smith

Email:  william@myemail.com

Valid Passport? No

    • If the Traveller does not have any reservations, then the message about their reservations must say: “[name] does not have any reservations”.  Example:

Name:  William Smith

Email:  william@myemail.com

Valid Passport? No

William Smith does not have any reservations.

    • If the Traveller does have reservations, then the message about their reservations should output the total number of reservations and the details about each reservation, for example:

Name:  William Smith

Email:  william@myemail.com

Valid Passport? Yes

Total Reservations:  2

Reservation ID:  01583

Date of Departure: 2022-04-01

Departing DFW, Arriving ICN on Flight #AA281

Reservation ID:  91119

Date of Departure: 2022-12-15

Departing LHR, Arriving CDG on Flight #KL1000

Main.swift

In your Main file, write the code to perform the following tasks. Where appropriate, your program must use the Flight, Reservation, and Traveller class properties and functions.

  1. Create the following flight objects

Flight Number

Departure  Airport

Arrival Airport

Distance (miles)

AA281

DFW

ICN

6835.70

KL1000

LHR

CDG

212.38

  1. Create two customers with names and email addresses of your choice
    • Traveller #1 must be initialized with a valid passport number: (example: 80153)
    • Traveller #2 must be initialized with an invalid passport number (example: 500)
  2. After creating your flight and customer objects, write the code to perform the following tasks:
    • Create a reservation for Traveller #1 on AA281. Output a message indicating if the reservation was made.
    • Create another reservation for Traveller #1 on KL1000. Output a message indicating if the reservation was made.
  3. Call Traveller #1’s display() function to show the Traveller’s information and reservations.
  4. Output the total cost of Traveller #1’s reservations
  5. Output the total amount Traveller 1 owes.
  6. Create a reservation for Traveller #2.  Output a message indicating if the reservation was made.
  7. Output the total amount Traveller #2 owes.

Please ensure that your output contains sufficient \n ,  whitespacing, and   - - - -  separator text  so that it is easy to read/find the output for traveller 1 vs. the output for traveller 2.   See SAMPLE OUTPUT for an example.

SAMPLE PROGRAM OUTPUT

- - - -

Reservation for traveller 1 created successfully? true

Reservation for traveller 1 created successfully? true

Name: William Smith

Email: william@myemail.com Passport Number: Yes

Total reservations: 2

Reservation ID 6658L

Date of Departure: 2022-04-01

Departing DFW, Arriving ICN on F ight #AA281

Reservation ID 1922S

Date of Departure: 2022-04-01

Departing LHR, Arriving CDB on F ight #KL1000

William Smith owes: $3015.1150000000002

- - - -

Reservation for traveller 2 created successfully? false

Name: Peter Moore

Email: peter.moore@abc.com

Passport Number: No

Peter Moore does not have any reservations

Peter Moore owes: $0.0

-END OF ASSESSMENT-

Option 1

Low Cost Option
Download this past answer in few clicks

16.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE