Skip to content

Conversation

CoraJacobson
Copy link

Copy link

@swift-student swift-student left a comment

Choose a reason for hiding this comment

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

Cora, you demonstrated that you are understanding the concepts extremely well. Overall, another solid submission. You should have no problem with the sprint challenge this weekend!

let destination: Airport
var terminal: String?
var departureTime: String?
var status: (FlightStatus, Timing?)

Choose a reason for hiding this comment

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

Very nice use of a tuple here! The only thing I would suggest is possibly naming the elements of the tuple so that it is more clear when you use them later, such as line 63. I can't think of what you would name the first element though, except maybe just flightStatus. So you would have status.flightStatus and status.timing. It's not too hard to follow with just two un-named elements though.

Comment on lines +58 to +79
func alertPassengers() {
for flight in departures {
if flight.terminal == nil {
print("Please see the nearest information desk about \(flight.airline) Flight \(flight.number) to \(flight.destination.name).")
} else {
switch flight.status.0 {
case .scheduled:
print("\(flight.airline) Flight \(flight.number) to \(flight.destination.name) is scheduled to depart at \(flight.departureTime ?? "TBD") from Terminal: \(flight.terminal ?? "TBD")")
case .canceled:
print("We're sorry \(flight.airline) Flight \(flight.number) to \(flight.destination.name) was canceled, here is a $500 voucher.")
case .enRoute:
print("\(flight.airline) Flight \(flight.number) is en route, and scheduled to land at Terminal: \(flight.terminal ?? "TBD")")
case .landed:
print("\(flight.airline) Flight \(flight.number) has landed at Terminal: \(flight.terminal ?? "TBD")")
case .boarding:
print("\(flight.airline) Flight \(flight.number) is boarding, please head to Terminal: \(flight.terminal ?? "TBD") immediately. The doors are closing soon.")
case .departed:
print("\(flight.airline) Flight \(flight.number) has departed from Terminal: \(flight.terminal ?? "unknown")")
}
}
}
}

Choose a reason for hiding this comment

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

Nicely written alert function. The switch statement makes things very easy to read.

Comment on lines +99 to +112
func time(hour: Int, minute: Int) -> String {
var timeComponents = DateComponents()
timeComponents.hour = hour
timeComponents.minute = minute
let userCalendar = Calendar.current
let time = userCalendar.date(from: timeComponents)
if let unwrappedTime = time {
let formatter = DateFormatter()
formatter.timeStyle = .short
return formatter.string(from: unwrappedTime)
} else {
return "TBD"
}
}

Choose a reason for hiding this comment

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

Nice helper function! You are thinking like a developer here.

Comment on lines 156 to 175
func printDepartures2(departureBoard: DepartureBoard) {
print("Departures for \(jfkDepartures.airport.abbreviation) - \(jfkDepartures.airport.name) in \(jfkDepartures.airport.location)")
for flight in jfkDepartures.departures {
if flight.departureTime == nil && flight.terminal == nil {
print("Destination: \(flight.destination.name) - \(flight.destination.abbreviation) Airline: \(flight.airline) Flight #: \(flight.number) Departure Time: Terminal: Status: \(flight.status.0.rawValue)\(flight.status.1?.rawValue ?? "")")
} else if flight.departureTime != nil && flight.terminal == nil {
if let time = flight.departureTime {
print("Destination: \(flight.destination.name) - \(flight.destination.abbreviation) Airline: \(flight.airline) Flight #: \(flight.number) Departure Time: \(time) Terminal: Status: \(flight.status.0.rawValue)\(flight.status.1?.rawValue ?? "")")
}
} else if flight.departureTime == nil && flight.terminal != nil {
if let terminal = flight.terminal {
print("Destination: \(flight.destination.name) - \(flight.destination.abbreviation) Airline: \(flight.airline) Flight #: \(flight.number) Departure Time: Terminal: \(terminal) Status: \(flight.status.0.rawValue)\(flight.status.1?.rawValue ?? "")")
}
} else if let time = flight.departureTime {
if let terminal = flight.terminal {
print("Destination: \(flight.destination.name) - \(flight.destination.abbreviation) Airline: \(flight.airline) Flight #: \(flight.number) Departure Time: \(time) Terminal: \(terminal) Status: \(flight.status.0.rawValue)\(flight.status.1?.rawValue ?? "")")
}
}
}
}

Choose a reason for hiding this comment

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

I would challenge you to see if you can do this with only one print statement. One way to approach it would be to set up a variable to a default value, and if you can unwrap your optional, set that variable to the unwrapped value.

var terminal = ""
if let flightTerminal = flight.terminal {
    terminal = flightTerminal
}

// terminal is now equal to either an empty string "" or the unwrapped flight terminal

Comment on lines +212 to +221
func calculateAirfare(checkedBags: Int, distance: Int, travelers: Int) -> String {
let airfare = ((Double(checkedBags) * 25) + (Double(distance) * 0.10)) * Double(travelers)
let formatter = NumberFormatter()
formatter.numberStyle = .currency
if let formattedAirfare = formatter.string(for: airfare) {
return formattedAirfare
} else {
return "invalid input"
}
}

Choose a reason for hiding this comment

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

Very nice work! Great use of the formatter, and defaulting to "invalid input"

@CoraJacobson
Copy link
Author

@swift-student
Revised Step 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants