Giter VIP home page Giter VIP logo

sales-taxes's Introduction

Build Status

Sales Taxes

Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions.

When I purchase items I receive a receipt which lists the name of all the items and their price (including tax), finishing with the total cost of the items, and the total amounts of sales taxes paid. The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.

Assumptions

Input format

The input format is intended as the one outlined in the examples so I suppose a file in that format should be given to the program for parsing before any processing.

The implemented parser (TextualBasketParser) implements the interface BasketParser that accept an InputStream and returns the parsed basket as a POJO so that more parsers can be added if needed.

Within the data/ directory are provided the three baskets stated in the problem description.

Output format

The output format is intended as the one in the examples so I suppose the user wants the ability to output it to a file.

The implemented writer (TextualReceiptWriter) implements the interface ReceiptWriter that accept a Receipt and returns a string representation of it so that more parsers can be added if needed.

Products categories

I suppose that a file containing the categories of the various products is supplied at startup, the file is such that:

  • is a CSV with two columns:
    • product, that is the product name (possibly without the imported verb)
    • category, that is the category to which it belongs

Moreover I assumed the following:

  • each product has one and only one category
  • if a product cannot be found within categories it's supposed to be eligible for the basic sales tax
  • categories can be held in memory. A HashMap has been used to store them, otherwise they should be saved persistently on a DB or the file read by chunk

Within the data/ directory is provided an example of the categories CSV file.

Build the application

The application can be build with Maven:

mvn clean instal

Run the application

The application is written in Java using Oracle's JDK11:

java -jar SalesTaxes 
    -c "/path/to/categories.csv" 
    -b "/path/to/basket.txt" 
    -e "food","books","medical" 
    -o "/path/to/result.txt"

Giving no arguments the help is printed:

usage: SalesTaxes
 -c,--categories <arg>   the categories file path
 -b,--basket <arg>       the shopping basket file path
 -e,--exclude <arg>      categories excluded from base tax
 -o,--output <arg>       the file to which output the receipt

Solutions

The test SalesTaxesProblemsTest contains three test cases for the three problem stated in the problem description.

Assumption

  • in problem #1 output a wrongly placed space character has been removed between "book" and ":"
  • problem #3 the last product differ from input to output, "box of imported chocolates" and "imported box of chocolates" respectively, the former has been chosen

sales-taxes's People

Contributors

arci avatar

Watchers

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