-
Notifications
You must be signed in to change notification settings - Fork 241
Completed project - Cora Jacobson #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Completed project - Cora Jacobson #165
Conversation
There was a problem hiding this 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?) |
There was a problem hiding this comment.
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.
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")") | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.
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" | ||
} | ||
} |
There was a problem hiding this comment.
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.
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 ?? "")") | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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
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" | ||
} | ||
} |
There was a problem hiding this comment.
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"
@swift-student |
@swift-student