Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
76 changes: 72 additions & 4 deletions AirportDepartures.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -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)



Expand All @@ -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.
Expand All @@ -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
Expand Down