Giter VIP home page Giter VIP logo

publictransportationkata's Introduction

Public Transportation Kata

Scenario

Our company has recently bought a train company. The trains run between between train stations. A train station is geographically situated in a zone, some stations are situated on the boundary of a zone which means they are classed as being within 2 zones. Zones are a set of concentric circles which start at the centre of the city. Zone 1 is at the centre of the city and Zone 4 is the furthest away from the city.

Pricing is dependent upon:

  1. Which zone(s) you travel between.
  2. What train stations are situated on a zone boundary, say zones 2 and zone 3, these have a specific pricing rule. The customer is charged the lowest fare, for instance if you are travelling from zone 1 to a station on the boundary of zone 2 and 3 then you will be charged the fare of zone 1 to zone 2.
  3. You are charged per trip.

Stations and zones

Zone 1 stations:

  • A
  • B

Zone 2 stations:

  • C
  • D
  • E

Zone 3 stations:

  • C
  • E
  • F

Zone 4 stations:

  • F
  • G
  • H
  • I

Pricing

We charge in euros (€), a euro has 100 cents.

  1. Travel within zones 1 and 2: €2.40 per trip.
  2. Travel within zones 3 and 4: €2.00 per trip.
  3. Travel from zone 3 to zone 1 or 2: €2.80 per trip.
  4. Travel from zone 4 to Zone 1 or 2: €3.00 per trip.
  5. Travel from zone 1 or 2, to zone 3: €2.80 per trip.
  6. Travel from zone 1 or 2, zone 4 to: €3.00 per trip.
  7. If there is the possibility of two prices then we must charge the customer the lowest amount and reflect this in the pricing information.

Test objective

We bill customers at the end of the day, based on an input file which contains all customer journeys. You need to write a process that from the input file passed in at the command line will generate a summary of the customers trips and total costings. The input file and output files are defined and an example of each are included, see " CandidateInputExample.txt" and "CandidateOutputExample.txt". To help with understanding the relationship between the input and output we have given time values as small integers, we know you can not travel between stations in one millisecond! The input file given, when passed as a path to your program as the first command line parameter and the output file path passed as the second command line parameter, must generate the valid JSON output of the given output file (differences in whitespace and ordering are of course permitted - as per the JSON standard).

A customer always "taps" their customer travel card at a barrier/gate which allows us to record their entry and then their exit with a second "tap" as the leave at the destination. You can assume that:

  1. For each customers' journey we always get an entry and exit tap pair in a file. An entry will always be before an exit.
  2. The customers first tap represents an entry at the beginning of the journey and the second tap their exit at the end of the journey.
  3. A customer may have multiple journeys in a day.

Input File explanation

A snippet of input file has the following format:

{
  "taps": [
    {
      "unixTimestamp": 1572242400,
      "customerId": 1,
      "station": "A"
    },
    {
      "unixTimestamp": 1572244200,
      "customerId": 1,
      "station": "D"
    },
    {
      "unixTimestamp": 1572282000,
      "customerId": 1,
      "station": "D"
    },
    {
      "unixTimestamp": 1572283800,
      "customerId": 1,
      "station": "A"
    }
  ]
}

This represents customer who had id 1 taking a journey from station A at the unix time of 1572242400 which represents 2019-10-28T06:00+00:00 and complete their journey by exiting Station D at the unix time of 1572244200 which represents 2019-10-28T06:30+00:00. The customer then returns to the opposite direction at 2019-10-28T17:30+00:00 (1572282000).

Output File explanation

The output file has the following format:

{
  "customerSummaries": [
    {
      "customerId": 1,
      "totalCostInCents": 480,
      "trips": [
        {
          "stationStart": "A",
          "stationEnd": "D",
          "startedJourneyAt": 1572242400,
          "costInCents": 240,
          "zoneFrom": 1,
          "zoneTo": 2
        },
        {
          "stationStart": "D",
          "stationEnd": "A",
          "startedJourneyAt": 1572282000,
          "costInCents": 240,
          "zoneFrom": 2,
          "zoneTo": 1
        }
      ]
    }
  ]
}

For each customer we output:

  1. "customerId" - the customer's identifier
  2. "totalCostInCents" - the total cost of the days journeys in cents

For each of the customers' trips we output the following:

  1. "stationStart" - the station where the journey started at.
  2. "stationEnd" - the station where the journey ended at.
  3. "startedJourneyAt" - the time when journey started at.
  4. "costInCents" - the cost of the journey in cents.
  5. "zoneFrom" the zone which the user was charged from.
  6. "zoneTo" - the zone which the user was charged to.

Requirements for compiling and launching the application

This appliction uses Record new feature from Java 16 so you will need Java 16 to compile and execute it.

To package the application, just launch:

mvn clean package

You will have 2 jar files :

  • One without dependencies
  • One with integrated dependencies with suffix : jar-with-dependencies

For execution, classical way of doing:

java -jar kata-1.0-SNAPSHOT-jar-with-dependencies.jar path/to/inputFile.json path/to/outputFile.json

Enjoy !

publictransportationkata's People

Contributors

acourtes 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.