-
Notifications
You must be signed in to change notification settings - Fork 241
Completed Project #173
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 #173
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.
Overall, another solid assignment from you, James! You seem to be understanding the material well. You should have no problems with the sprint challenge this weekend.
func printDepartures2(departureBoard: DepartureBoard) { | ||
for flight in departureBoard.departureFlights { | ||
let flightTerminal = flight.terminal ?? "" | ||
if let departureTime = flight.time { | ||
print("Destination: \(flight.destination) Airline: \(flight.airline) Flight: \(flight.flightID) Departure Time: \(departureTime) Terminal: \(flightTerminal) Status: \(flight.status.rawValue)") | ||
} else { | ||
print("Destination: \(flight.destination) Airline: \(flight.airline) Flight: \(flight.flightID) Departure Time: Terminal: \(flightTerminal) Status: \(flight.status.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.
Love what you came up with here. Very clean with only two print statements and using the nil coalescing operator.
func convertDoubleToCurrency(amount: Double) -> String { | ||
let numberFormatter = NumberFormatter() | ||
numberFormatter.numberStyle = .currency | ||
numberFormatter.locale = Locale.current | ||
return numberFormatter.string(from: NSNumber(value: amount)) ?? "" | ||
} |
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.
Hell yeah! Great helper function! Way to think like a developer.
//: d. Print out the current DepartureBoard you created using the function | ||
func printDepartures(departureBoard: DepartureBoard) { | ||
for flight in departureBoard.departureFlights { | ||
print("The Flight is \(flight.status.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.
Nice use of .rawValue
let orlandoFlight = Flight(status: .Scheduled, terminal: "7", | ||
time: Date(), destination: "Orlando", airline: "Delta Air Lines", flightID: "KL 6966") |
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 appreciate the return to keep it from line wrapping. Thoughtful.
case EnRoute = "En Route" | ||
case Scheduled = "Scheduled" | ||
case Canceled = "Canceled" | ||
case Delayed = "Delayed" | ||
case Boarding = "Boarding" |
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.
Not a huge deal, but enum cases should be lower cased, as they are not a type:
enum FlightStatus: String {
case enRoute = "En Route"
case scheduled = "Scheduled"
case canceled = "Canceled"
case delayed = "Delayed"
case boarding = "Boarding"
}
switch flight.status { | ||
case .Boarding: | ||
if let flightTerminal = flight.terminal { | ||
print("Your flight is boarding, please head to terminal: \(flightTerminal) immediately. The doors are closing soon.") | ||
} else { | ||
print("See the nearest information desk for more details.") | ||
} | ||
case .Canceled: | ||
print("We're sorry your flight to (city) was canceled, here is a $500 voucher") | ||
case .Delayed: | ||
print("We're sorry, your flight is delayed.") | ||
case .EnRoute: | ||
print("Your flight is en route.") | ||
case .Scheduled: | ||
if let flightTime = flight.time { | ||
if let flightTerminal = flight.terminal { | ||
print("Your flight to \(flight.destination) is scheduled to depart at \(flightTime) from terminal: \(flightTerminal)") | ||
} else { | ||
print("See the nearest information desk for more details.") | ||
} | ||
} | ||
} |
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 switch statement! I will say that convention in Swift is for the cases to be at the same indentation as the switch keyword. ctrl-i in Xcode produces this:
func upcomingFlightAlert(flight: Flight) {
switch flight.status {
case .Boarding:
if let flightTerminal = flight.terminal {
print("Your flight is boarding, please head to terminal: \(flightTerminal) immediately. The doors are closing soon.")
} else {
print("See the nearest information desk for more details.")
}
case .Canceled:
print("We're sorry your flight to (city) was canceled, here is a $500 voucher")
case .Delayed:
print("We're sorry, your flight is delayed.")
case .EnRoute:
print("Your flight is en route.")
case .Scheduled:
if let flightTime = flight.time {
if let flightTerminal = flight.terminal {
print("Your flight to \(flight.destination) is scheduled to depart at \(flightTime) from terminal: \(flightTerminal)")
} else {
print("See the nearest information desk for more details.")
}
}
}
}
func calculateAirfare(checkedBags: Int, distance: Int, travelers: Int) -> Double { | ||
let bagCost: Double = 25.00 | ||
let costPerMile: Double = 0.10 | ||
let totalBagCost = Double(checkedBags) * bagCost | ||
let totalMileCost = Double(distance) * costPerMile | ||
let airfareTotal: Double = (totalBagCost + totalMileCost) * Double(travelers) | ||
return airfareTotal | ||
} |
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 clear and easy to understand your logic here.
@swift-student
// I wanted to work on this some more to complete all the stretch goals, but just ran out of time