Code Monkey home page Code Monkey logo

trip-fare-calculator's Introduction

TRIP FARE CALCULATOR

This application calculates fares according to the below calculation.

Trips between Stop 1 and Stop 2 cost $3.25
Trips between Stop 2 and Stop 3 cost $5.50
Trips between Stop 1 and Stop 3 cost $7.30

Note that the above prices apply for travel in either direction (e.g. a passenger can tap on at stop 1 and tap off at stop 2, or they can tap on at stop 2 and can tap off at stop 1. In either case, they would be charged $3.25).

It reads an input file (taps.csv) from a preconfigured /resources folder and maps it to an output file (trips.csv)

Sample Input

ID, DateTimeUTC, TapType, StopId, CompanyId, BusID, PAN
1, 22-01-2018 13:00:00, ON, Stop1, Company1, Bus37, 5500005555555559
2, 22-01-2018 13:05:00, OFF, Stop2, Company1, Bus37, 5500005555555559

Sample Output

Started, Finished, DurationSecs, FromStopId, ToStopId, ChargeAmount, CompanyId, BusID, PAN,
Status
22-01-2018 13:00:00, 22-01-2018 13:05:00, 900, Stop1, Stop2, $3.25, Company1, B37,
5500005555555559, COMPLETED

Prerequisites

  • Install Java
  • Install Maven

How to run the application

  • Run mvn clean install in the root folder
  • Run mvn spring-boot:run -Dspring-boot.run.arguments=src/main/resources/taps.csv in the root folder to run the application
  • Output csv can be found in the root folder as well once the application has run successfully

NOTE:

  • If new fare data are to be added, add them to the /resources/fares.csv
  • To input a different test file simply replace the file path - src/main/resources/taps.csv in the command line arguments in the run command

Tests

Unit tests

  • Run mvn test inside root folder to run tests

Automated tests

  • Run TripFareProcessorTest

Assumptions

  • There cannot be a Tap Type 'OFF' record without an 'ON' record
  • csv data are ordered by timestamp
  • In incomplete trips, finished time and last stop is null
  • Cannot have 2 'ON' taps at the same stop

Improvements

  • Improve to list the stop the fare is calculated against in incomplete trips.
  • Improve unit tests to include unhappy paths

trip-fare-calculator's People

Contributors

dinuish94 avatar

Watchers

 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.