Code Monkey home page Code Monkey logo

checkoutkata's Introduction

Checkout Kata

Implement the code for a supermarket checkout that calculates the total price of a number of items.

In a normal supermarket, items are identified by ‘stock keeping units’ or ‘SKUs’. In our store, we will use individual letters of the alphabet, A, B, C etc, as the SKUs. Our goods are priced individually. In addition, some items are multipriced: buy n of them and which will cost you y. For example, item A might cost 50 pence individually but this week we have a special offer where you can buy 3 As for £1.30.

This week’s prices are the following:

  • Item A | Unit Price: 50 | Special Price: 3 for 130
  • Item B | Unit Price: 30 | Special Price: 2 for 45
  • Item C | Unit Price: 20
  • Item D | Unit Price: 15

Our checkout accepts items in any order so if we scan a B, then an A, then another B, we will recognise the two B’s and price them at 45 (for a total price so far of 95).

Extra points: Because the pricing changes frequently we will need to be able to pass in a set of pricing rules each time we start handling a checkout transaction.

Approach

  • The Design Pattern used in this application followed a TDD Approach with the use of Object-Oriented design principles known as SOLID
    • within Solid patterns This application makes use of Single Responsibility Principle which gives the quality assurance that the Open-Close Principle is also met
    • The application also enforce the use of loose coupling and high cohesion
    • The application also enforces encapsulation, Overloading, and Composition through a HAS-A relationships between entities
      • i.e (between Product : StockItems) One to Many Relationship
    • Enforces the use Functional Programming and Lambda Functions
    • With the use OOP approach opens flexibility for reusable code and possible future migrations
    • i.e(making use of constants to make it easier for future change to a final variable in one location)
    • The logic, presentation entities and views are well separated and managed

Application

  • This is a standalone console application with no com.challenge.checkoutKata.UI
  • The com.challenge.checkoutKata.UI Class is the runner class which contains static main function
  • Extensive use of assertions within Unit test, ensures to test the classes and its methods
    • the CheckoutTest Class handles the different edge cases
  • Classes like Checkout and Basket class consists of operations which occurs in a real world
    • i.e: a shopping cart with a list of items and the no of occurrence including returning the total price of each item occurrence in the basket.
  • To run the application - "UI.Java" is the main file and I have also added a jar file including the unit tests.
    • Application Framework uses Maven and Java 8 with no third-Party libraries or dependencies, it should be straightforward to spin up on a local machine
      • "mvn clean install" to build the project as well as run the test
      • "mvn test" to run just the test

Application Functionality

  • To keep track of operations made between menu option 2 and menu option, it stores the wholesale and inventory list in a file located under resources
    • Unit tests also has its files for both the Inventory and wholesale list
  • There are three menu options on the initial run of the application:
    • To do shopping by adding items into the cart and a receipt is generated
      • validator - ensures to validate input with an existing Sku/itemName
    • To add or remove a stock item, once operation is completed it is updated in the file, making it reusable - It also avoids duplicate item name (SKUs) to be added in the inventory list
    • To add or remove a Special Pricing rule for an item, once operation is completed it is updated in the file, making it reusable
      • It avoids duplicating Pricing rule with same itemName and no of item on offer

checkoutkata's People

Contributors

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