Skip to content
Open
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
109 changes: 109 additions & 0 deletions Stephanie_Ride_Share.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

drivers = {
DR0001: [
{
trip_date: "3rd Feb 2016",
cost: 10,
rider_id: "RD0003",
rating: 3
},
{
trip_date: "3rd Feb 2016",
cost: 30,
rider_id: "RD0015",
rating: 4
},
{
trip_date: "5th Feb 2016",
cost: 45,
rider_id: "RD0003",
rating: 2
}
],
DR0002: [
{
trip_date: "3rd Feb 2016",
cost: 25,
rider_id: "RD0073",
rating: 5
},
{
trip_date: "4th Feb 2016",
cost: 15,
rider_id: "RD0013",
rating: 1
},
{
trip_date: "5th Feb 2016",
cost: 35,
rider_id: "RD0066",
rating: 3
}
],
DR0003: [
{
trip_date: "4th Feb 2016",
cost: 5,
rider_id: "RD0066",
rating: 5
},
{
trip_date: "5th Feb 2016",
cost: 50,
rider_id: "RD0003",
rating: 2
}
],
DR0004: [
{
trip_date: "3rd Feb 2016",
cost: 5,
rider_id: "RD0022",
rating: 5
},
{
trip_date: "4th Feb 2016",
cost: 10,
rider_id: "RD0022",
rating: 4
},
{
trip_date: "5th Feb 2016",
cost: 20,
rider_id: "RD0073",
rating: 5
}
]
}


driver_pay = 0
max_driver = ""
max_pay = 0
driver_rating = 0.0
best_driver = ""
best_rating = 0.0


drivers.each { |driver, drive|
drive.each { |drives|
driver_pay += drives[:cost]
driver_rating += drives[:rating]
}
if driver_pay > max_pay
max_pay = driver_pay
max_driver = driver
end
driver_rating = (driver_rating / drive.length).round(2)
if driver_rating > best_rating
best_driver = driver
best_rating = driver_rating
end
puts "Driver #{driver} gave #{drive.length} rides and made a total of $#{driver_pay}.00.
Their average rating is #{driver_rating}"
driver_pay = 0
driver_rating = 0.0
}
Comment on lines +88 to +106

Choose a reason for hiding this comment

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

This works and it's pretty readable, but I suggest looking at breaking each step into a method for practice breaking code into components.

It's also pretty dense.


puts "Driver #{max_driver} made the most money with a total earnings of $#{max_pay}.00"
puts "Driver #{best_driver} has the highest rating at #{best_rating}"