Tasks
Task 1 - Setting up the scanner
Let's implement some code for a supermarket checkout that calculates the total price of a number of items. In a normal supermarket, things are identified using Stock Keeping Units, or SKUs. In our store, we’ll use individual letters of the alphabet (A, B, C, and so on). Our goods are priced individually, and the prices for each item can be found in the table below.
Item Code | Price |
---|---|
A | 50 |
B | 30 |
C | 20 |
D | 15 |
It's important to note that these price rules are subject to frequent change, so your code needs to be flexible to allow for this.
Our checkout accepts items in any order, and only one item at a time. The interface for the checkout looks like this (shown in Java):
Checkout co = new Checkout(pricingRules);
co.scan(item1);
co.scan(item2);
co.total();
Your task is to implement a checkout system that fulfils these requirements and calculates the total price for the basket ACBDABAAD
Task 2 - Special offers
Now that the initial scanning functionality has been setup, it's time to add some promotions! Our supermarket now has a special offer on particular items:
- Buy 'n' items of a SKU for a fixed price (3 A's for 130)
- Buy 'n' of an item, get 'm' for free (Buy 1 of D, get the next 1 for free)
Our checkout system will need to calculate the total price of the basket, taking into account any special offers.
Item Code | Price | Special Offers |
---|---|---|
A | 50 | 3 for 130 |
B | 30 | 2 for 45 |
C | 20 | |
D | 15 | Buy 1 get 1 free |
Your task is to implement these special offers in the checkout system, and re-calculate the total price of the basket ACBDABAAD
Task 3 - Bulk order
To test how much your scanner can handle, let's put through a bulk order!
Calculate the total for the following basket ADDBCABDAACDDACDBACBABCDABBCCDA
Final Answer
The final answer is in the form of xxx-yyy-zzz, where xxx and yyy and zzz are the answers to the three tasks above.