Coder Social home page Coder Social logo

uber-lyft-methods-lab's Introduction

Uber Fare Estimator Lab

uber and lyft

How do Uber and Lyft figure out how much to charge passengers for their rides? They have a set of instructions (an algorithm) that takes in important information like distance, time, traffic, and number of passengers to figure out what price to set for a trip.

In this lab, you'll be writing ruby methods to calculate fares for various ride services. Take a look at this chart, which provides the most recent fares for Uber services.

Initial Fee Price Per Mile Price Per Minute Service Cost
uberX $0.40 $0.97 $0.14 $1.58
uberXL $2.15 $1.68 $0.26 $1.70
UberSELECT $4.02 $2.17 $0.33 $1.70
UberBLACK $7.22 $3.33 $0.44 $1.80

Instructions

  1. Create a function called simple_uberx_fare that only accepts miles and returns the fare based on that number of miles.

Example: When I run simple_uberx_fare(10) for 10 miles, it should return $9.70 because the uberX price per mile is $0.97.

  1. Create a function called uberx_fare_calculator that takes in both the distance and the amount of time for the ride. It should integrate the initial fee, price per mile, price per minute and the service cost to return a estimated fare for a ride.

Example: For a ride that is 2 miles and 10 minutes: uberx_fare_calculator(2, 10) should return $5.32 ($0.40 initial fee, 2 miles at $0.97/mile, 10 minutes at $0.14/minute, $1.58 service cost)

  1. Create a more flexible fare calculator method called fare_calculator that takes in the distance, the time, and the type of ride.

Example: For a ride that is 2 miles and 10 minutes in an UberXL: fare_calculator(2, 10, "UberXL") should return $9.81 ($2.15 initial fee, 2 miles at $1.68/mile, 10 minutes at $0.26/minute, $1.70 service cost)

Bonus: if no car type is given, have fare_calculator default to "UberX"

Advanced Bonus Challenge:

  1. Uber, Lyft or Cab?: Look up the fares of using Lyft and yellow cabs in New York City and create a method cheapest_ride that accepts the distance and the time as parameters, and returns the cheapest service to take for that trip, along with the fare estimate. This is an open ended one - there are many ways to do this!

uber-lyft-methods-lab's People

Contributors

dfenjves avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.