Our Java coding exercise is inspired by PragDave Supermaket Kata.
[...] to experiment with various models for representing money and prices that are flexible enough to deal with [a variety of] pricing schemes, and at the same time are generally usable (at the checkout, for stock management, order entry, and so on).
This project provides the code for an initial model of a supermarket. The supermarket's inventory consists of products that can be sold by unit (e.g. a can of baked beans) or by weight (e.g. loose carrots). The total price of a shopping basket has currently been calculated as a simple sum of its items.
The supermarket would like to offer pricing discount schemes, for example:
- Buy one, get one free
- Buy two items for £1
- Buy three items for the price of two
- Buy one kilo of vegetables for half price
Some discounts would be applicable for single products (e.g. a can of baked beans), while others could apply across a group of products (e.g. vegetables).
Your task is to extend the functionality of Basket to implement a component that can calculate the total amount to pay for the items in a basket, including any discounts that would be applicable for the current state of the basket.
- You should think about how the relationships between Basket, Item, and Product will need to be refactored to achieve this
- You should consider how your solution could be extended to provide more complicated discount schemes
First and foremost this is an opportunity for you to demonstrate your software design skills within a small problem space.
Please read through the description carefully and implement a solution that includes at least one of the pricing discount schemes described.
We would like you spend no more than one hour on this task.
- Clean, tidy, tested, and working code (with accurate pricing calculations)
- Use of appropriate design patterns and SOLID principles
- Small incremental changes with good comments, as demonstrated in your commit history
Above all, we would rather see a small codebase with fewer features than failure to observe the points above.
You may add any libraries you feel are appropriate. But we don't expect to see databases or other persistence layers, dependency injection frameworks, web servers, REST APIs, or web frameworks; we are not looking for a fully functioning supermarket system!
- Plan your time before you start coding. Start small and add features incrementally
- Focus on the pricing model and the behaviour of your components -- you only need to demonstrate that your design works, rather than an exhaustive model of numerous supermarket items
- If you run out of time, describe your intentions in the NOTES.md file
We really don't want you to over-engineer the solution -- and you really don't have time for that! -- but be prepared to extend the functionality in the next step of the interview process.
Clone or fork this project into a publicly accessible git repository of your own, and email the URL to to tpadberg@qmetric.co.uk.
Good Luck!