Skip to content
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f8189d4
Create MiguelsProject
Marquez5301 May 6, 2020
1f63b64
Delete MiguelsProject
Marquez5301 May 6, 2020
6e65733
Update Contents.swift
Marquez5301 May 6, 2020
5e459ce
First revision, I added a FlightStatus enum in line 20
Marquez5301 May 7, 2020
c528326
Second revision, I added an Airport struct at line 29
Marquez5301 May 7, 2020
18e6f77
Third revision, I added a DepartureBoard class at line 44
Marquez5301 May 7, 2020
5efd7dc
Fourth revision, I added a a Flight struct aat line 60
Marquez5301 May 7, 2020
f48f00a
Fifth revision, I added a reference of DepartureBoard called myDeparture
Marquez5301 May 7, 2020
d27ec6d
Sixth revision, I added three instances to my Flight array and I appe…
Marquez5301 May 7, 2020
fceb172
Seventh revision, I added a For Loop to my ENUM
Marquez5301 May 7, 2020
a8d9733
Eighth revision, I re-wrote a For Loop with Case iteration on line 102
Marquez5301 May 7, 2020
b6d6f85
Ninth revision, I fixed myDeparture instance on line 84
Marquez5301 May 7, 2020
ffa3ab6
Tenth revision, I renamed OtherFlightStatus to FlightStatus2 on line 102
Marquez5301 May 7, 2020
a15176a
Eleventh revision, fixed my code on line 103
Marquez5301 May 8, 2020
557dedc
Twelfth revision, added a Date command at lines, 64, 71, 86, 87, 88
Marquez5301 May 8, 2020
0421a3e
Thirteenth revision, added NIL value at line 87
Marquez5301 May 8, 2020
c20827e
Fourteenth revision, I created a printDeparture2 func
Marquez5301 May 8, 2020
fcf7051
Fifteenth revision, I created an alertPassengers func on lines 147 -…
Marquez5301 May 8, 2020
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
105 changes: 95 additions & 10 deletions AirportDepartures.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

// New changes

//: ## 1. Create custom types to represent an Airport Departures display
//: ![Airport Departures](matthew-smith-5934-unsplash.jpg)
Expand All @@ -16,9 +17,60 @@ 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 FlighStatus: String {
case route = "On-Time"
case scheduled = "Scheduled"
case canceled = "Cancelled"
case delayed = "Delayed"
case boarding = "Boarding"
}


struct Airport {
let planes: Int
let hotel: String
let transport: String
let carRental: String

init(planes: Int, hotel: String, transport: String, carRental: String) {
self.planes = planes
self.hotel = hotel
self.transport = transport
self.carRental = carRental
}
}

class DepartureBoard {
let destination: String
let airline: String
let terminal: Int
let status: FlighStatus
var flights: [Flight]

init(destination: String, airline: String, terminal: Int, status: FlighStatus, flights: [Flight]) {
self.destination = destination
self.airline = airline
self.terminal = terminal
self.status = status
self.flights = []
}
}

struct Flight {
let pilots: Int
let attendants: Int
let passengers: Int
let ticketClass: String
let departureTime: Date?

init(pilots: Int, attendants: Int, passengers: Int, ticketClass: String, departureTime: Date?) {
self.pilots = pilots
self.attendants = attendants
self.passengers = passengers
self.ticketClass = ticketClass
self.departureTime = departureTime
}
}
//: ## 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 +81,15 @@ 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 myDeparture = DepartureBoard(destination: "West Palm Beach", airline: "Turkish Airlines", terminal: 5, status: .route, flights: [] )

var flight1 = Flight(pilots: 2, attendants: 2, passengers: 200, ticketClass: "Economy", departureTime: Date() )
var flight2 = Flight(pilots: 2, attendants: 4, passengers: 100, ticketClass: "Business", departureTime: nil )
var flight3 = Flight(pilots: 2, attendants: 4, passengers: 20, ticketClass: "First Class", departureTime: Date() )

myDeparture.flights.append(flight1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great way to append in to your class without creating a new variable. Good job.

myDeparture.flights.append(flight2)
myDeparture.flights.append(flight3)


//: ## 3. Create a free-standing function that can print the flight information from the `DepartureBoard`
Expand All @@ -41,8 +101,11 @@ import UIKit
//:
//: d. Print out the current DepartureBoard you created using the function

func printDeparture() {
for flights in myDeparture.flights {print(flights) }
}


printDeparture()

//: ## 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,9 +121,15 @@ 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() {
for flights in myDeparture.flights {
if flights.departureTime == nil {
print("This flights as no Date()")
} else { print(flights) }
}
}

printDepartures2()
//: ## 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.
//: a. If the flight is canceled print out: "We're sorry your flight to \(city) was canceled, here is a $500 voucher"
//:
Expand All @@ -75,9 +144,25 @@ 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.



func alertPassengers() {
for flights in myDeparture.flights
}

let flighStatus: FlighStatus = .route

print("What is the status of my flight?")

switch numberOfWheels {
case FlighStatus.route :
print("Your flight to (city) is scheduled to depart at (time) from terminal: (terminal)")
case FlighStatus.boarding :
print("Your flight is boarding, please head to terminal: (terminal) immediately. The doors are closing soon")
case FlighStatus.canceled :
print("We're sorry your flight to (city) was canceled, here is a $500 voucher")
case FlighStatus.delayed :
print("Your flight is curently delayed, we apologize for any inconvenience")
default:
print("There is no scheduled flight") }

//: ## 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 Down