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.
110 changes: 109 additions & 1 deletion AirportDepartures.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,81 @@ 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
import UIKit



enum FlightStatus: String {
case enRoute = "En Route"
case scheduled = "On Time"
case cancelled = "Canceled"
case delayed = "Dalayed"
}

struct Airport {
var city: String
var airportCode: String
}


struct Flight {

// var destinationAirport: Airport
var departureTime: Date?
var terminal: String?
var status: FlightStatus
var destination: Airport
var airline: String
var flightNumber: String
}

class DepartureBoard {
var flights: [Flight]
var airports: Airport



init(eFlight: [Flight], eAirport: Airport) {
self.flights = eFlight
self.airports = eAirport
}

}



let Hawaii = Airport(city: "Hawaii", airportCode: "001")
let LasVegas = Airport(city: "Las Vegas", airportCode: "002")
let SaltLake = Airport(city: "Salt Lake", airportCode: "003")

var cities = [Hawaii, LasVegas, SaltLake]
cities.append(Airport(city: "LA", airportCode: "004"))

//let flight1 = Flight(departureTime: nil, terminal: "2", status: .cancelled, destination: Hawaii, )
//let flight2 = Flight(departureTime: Date(), terminal: nil, status: .delayed, destination: LasVegas)
//let flight3 = Flight(departureTime: Date(), terminal: "1", status: .scheduled, destination: SaltLake)

let flight1 = Flight(departureTime: nil, terminal: "2", status: .cancelled, destination: Hawaii, airline: "JetBlue", flightNumber: "001")
let flight2 = Flight(departureTime: Date(), terminal: nil, status: .delayed, destination: LasVegas, airline: "Alaska", flightNumber: "002")
let flight3 = Flight(departureTime: Date(), terminal: "1", status: .scheduled, destination: SaltLake, airline: "American", flightNumber: "003")
let JFKDepartureBoard = DepartureBoard(eFlight: [flight1, flight2, flight3], eAirport: Hawaii)




//Use the Array append() method to add Flight's

func printDepartures(departureBoard: DepartureBoard) {
let departures = JFKDepartureBoard.flights

for departure in departures {
print("Destination:\(departure.destination), Airline:\(departure.airline), Flight:\(departure.flightNumber), Departure Time:\(departure.departureTime ?? Date()), Terminal:\(departure.terminal ?? ""), Status:\(departure.status) ")

}
}






Expand Down Expand Up @@ -44,6 +119,12 @@ 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

//: ## 4. Make a second function to print print an empty string if the `departureTime` is nil
//: a. Createa new `printDepartures2(departureBoard:)` or modify the previous function
//:
Expand All @@ -58,7 +139,7 @@ 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

printDepartures(departureBoard: JFKDepartureBoard)


//: ## 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 @@ -79,6 +160,13 @@ import UIKit










//: ## 6. Create a free-standing function to calculate your total airfair for checked bags and destination
//: Use the method signature, and return the airfare as a `Double`
//:
Expand All @@ -96,6 +184,26 @@ import UIKit
//: e. Make sure to cast the numbers to the appropriate types so you calculate the correct airfare
//:
//: f. Stretch: Use a [`NumberFormatter`](https://developer.apple.com/documentation/foundation/numberformatter) with the `currencyStyle` to format the amount in US dollars.
func calculateAirfare(checkedBags: Int, distance: Int, travelers: Int) -> Double {
var totalTicketPrice = 0.00
totalTicketPrice += Double(checkedBags) * 25.00
totalTicketPrice += Double(distance) * 0.10
return totalTicketPrice * Double(travelers)
}
print(calculateAirfare(checkedBags: 2, distance: 2000, travelers: 3))
//print(calculateAirfare(checkedBags: 3, distance: 3000, travelers: 4))
//print(calculateAirfare(checkedBags: 4, distance: 4000, travelers: 10))



//func totalAirFare(checkedBags: Double, distance: Double, travelers: Double) -> Double{
// let bagCost = 25 * checkedBags
// let distance = distance * 0.10
// let costOfTicket = (bagCost + distance * travelers)
// return costOfTicket
//}
//print(totalAirFare(checkedBags: 2, distance: 2000, travelers: 3))