/PointOfSaleTerminal

A class library for a point-of-sale scanning system

Primary LanguageTypeScript

Point of Sale Terminal

A point-of-sale scanning system class library. Accepts a list of products then calculates the total price given a preconfigured single and bulk cost. This scanning library has been designed to optimise for cost. The cheapest option of scanned items is always given.


Getting Started

// insatll dependencies
$ npm install
// transpile typescript into javascript
$ npm run build

Running Application Interface

$ npm run exec

You will be prompted to enter the scanned products. Products should be seperated by a comma (",").

eg. A,A,B,C,A,B,D,A

Available products include:

Product Scannable ID Single Price Bulk Price
apple A $1.25 3 for $3.00
banana B $4.25
candy C $1.00 6 for $5.00
date D $0.75

Running Test Cases

// runs a suite of tests on the PointOfSaleTerminal class
$ npm test

Documentation

PointOfSaleTerminal

constructors

  • PointOfSaleTerminal()
    const terminal = new PointOfSaleTerminal();

methods

  • setPricing(PriceModel[])

    sets pricing model

    terminal.setPricing([
        priceModelOne,
        priceModelTwo,
        priceModelThree
    ]);
  • scanProduct(string)

    scans a single product

    terminal.scanProduct('A');
  • calculateTotal()

    returns the total cost of all scanned products according to the pricing model.

    terminal.calculateTotal();

BulkPrice

constructors

  • BulkPrice(number, number)
    const bulkPrice = new BulkPrice(1, 3)

methods

  • getBulkCount()

    returns the number of items required to be a bulk

    bulkPrice.getBulkCount();
  • getPrice()

    returns the price for the bulk amount

    bulkPrice.getPrice();

PriceModel

constructors

  • PriceModel(string, BulkPrice[])
    const priceModel = new PriceModel('apples', [
        bulkPriceOne,
        bulkPriceTwo
    ]);

methods

  • getProductId()

    returns the bulk count

    priceModel.getProductId();
  • getPrices()

    returns the bulk price

    priceModel.getPrices();