From c49b0b81a418a3e5f13b23e7bd8f49e6ea920ce5 Mon Sep 17 00:00:00 2001 From: swiftalicious Date: Wed, 6 May 2020 16:10:51 -0700 Subject: [PATCH] Almost done --- .DS_Store | Bin 0 -> 6148 bytes AirportDepartures.playground/Contents.swift | 76 ++++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e36a6aa4427bbdee0507e932120bf0b8067bf758 GIT binary patch literal 6148 zcmeHKJx{|x41E_0YQ>Tb28N7GmHH1tl@1InRAQ!I3P>r5fDCN;DXjb({t-N%PgT;w zR0&ncmh6}KY)5_<#W?_OTrWpJ44_XHj0QA6h^&k5NEAHBMCWUic*ZL-tWfPlo8u4} zkiEOW6&|^B725kZ^Lts-uJD2(R}0MWhMb-fHJ-4%F3QEcDCevZe{IP=b&Gs7U6gBm zhoZaBeQH$??ON|Fg%ftWW-qyP*6x98AJj{2MM5#aEhgkA!wqrByiV7A@z1t0e3}_! zz!)$F4w?bZY?1z{qFH0W7%&Dl49NE(p$et}8%6)=pz%ilVvlYwyq2?sa0b`)cz>(g@GXE#P zpZ~i_c4rJ21OJKv*UP5am@S3by3?G@+Jt&f6_L0`ag)LeKZ+SEqxhWah5ke?h-tt^ RksgZu2zVOI7z2OGz&9#sV;leg literal 0 HcmV?d00001 diff --git a/AirportDepartures.playground/Contents.swift b/AirportDepartures.playground/Contents.swift index 98e2131..9f192db 100644 --- a/AirportDepartures.playground/Contents.swift +++ b/AirportDepartures.playground/Contents.swift @@ -16,8 +16,40 @@ import UIKit //: e. Use a `String?` for the Terminal, since it may not be set yet (i.e.: waiting to arrive on time) //: //: f. Use a class to represent a `DepartureBoard` with a list of departure flights, and the current airport - - +enum FlightStatus { + case enRoute + case scheduled + case landed + case canceled + case delayed + case boarding +} + +struct Airport { + var city: String + var code: String + + } + +struct Flight { + let destination: Airport + var airline: String + var flightNumber: String + var departureTime: Date? + var terminalNumber: String? + var flightStatus: FlightStatus +} + +class DepartureBoard { + var airport: Airport + var departures: [Flight] + + init(city: String, code: String) { + airport = Airport(city: city, code: code) + departures = [] + + } +} //: ## 2. Create 3 flights and add them to a departure board //: a. For the departure time, use `Date()` for the current time @@ -29,7 +61,20 @@ import UIKit //: d. Make one of the flights have a `nil` terminal because it has not been decided yet. //: //: e. Stretch: Look at the API for [`DateComponents`](https://developer.apple.com/documentation/foundation/datecomponents?language=objc) for creating a specific time +let lax = Airport(city: "Los Angeles", code: "LAX") +let mia = Airport(city: "Miami", code: "MIA") +let jfk = Airport(city: "New York", code: "JFK") + +let date = Date() + +let flightOne = Flight(destination: lax, airline: "United", flightNumber: "UA101", departureTime: Date(), terminalNumber: "1A", flightStatus: .boarding) +let flightTwo = Flight(destination: mia, airline: "American", flightNumber: "AA201", departureTime: Date(), terminalNumber: "2A", flightStatus: .delayed) +let flightThree = Flight(destination: jfk, airline: "Alaskan", flightNumber: "A333", departureTime: Date(), terminalNumber: "3A", flightStatus: .enRoute) +let laxDepartureBoard = DepartureBoard(city: "Los Angeles", code: "LAX") +laxDepartureBoard.departures.append(flightOne) +laxDepartureBoard.departures.append(flightTwo) +laxDepartureBoard.departures.append(flightThree) //: ## 3. Create a free-standing function that can print the flight information from the `DepartureBoard` @@ -40,6 +85,14 @@ import UIKit //: c. Make your `FlightStatus` enum conform to `String` so you can print the `rawValue` String values from the `enum`. See the [enum documentation](https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html). //: //: d. Print out the current DepartureBoard you created using the function +func printDepartures(departureBoard: DepartureBoard) { + + for flights in departureBoard.departures { + print("Destination: \(flights.destination) Airline: \(flights.airline) Flight Number: \(flights.flightNumber) Departure Time: \(flights.departureTime) Terminal Number: \(flights.terminalNumber) Flight Status: \(flights.flightStatus)") + } +} + +printDepartures(departureBoard: laxDepartureBoard) @@ -58,7 +111,14 @@ import UIKit //: Destination: Los Angeles Airline: Delta Air Lines Flight: KL 6966 Departure Time: Terminal: 4 Status: Canceled //: Destination: Rochester Airline: Jet Blue Airways Flight: B6 586 Departure Time: 1:26 PM Terminal: Status: Scheduled //: Destination: Boston Airline: KLM Flight: KL 6966 Departure Time: 1:26 PM Terminal: 4 Status: Scheduled +func printDepartures2(departureBoard: DepartureBoard) { + + for flights in departureBoard.departures { + print("Destination: \(flights.destination) Airline: \(flights.airline) Flight Number: \(flights.flightNumber) Departure Time: \(flights.departureTime) Terminal Number: \(flights.terminalNumber) Flight Status: \(flights.flightStatus)") + } +} +printDepartures2(departureBoard: laxDepartureBoard) //: ## 5. Add an instance method to your `DepatureBoard` class (above) that can send an alert message to all passengers about their upcoming flight. Loop through the flights and use a `switch` on the flight status variable. @@ -75,8 +135,16 @@ import UIKit //: d. Call the `alertPassengers()` function on your `DepartureBoard` object below //: //: f. Stretch: Display a custom message if the `terminal` is `nil`, tell the traveler to see the nearest information desk for more details. - - +//switch DepartureBoard { +//case lax: +// if flightOne.flightStatus = { +// print("We're sorry your flight to /(lax) was canceled, here is a $500 voucher") +// } +//case jfk: +// if flightTwo.flightStatus = +//default: +// +//} //: ## 6. Create a free-standing function to calculate your total airfair for checked bags and destination