-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREAD ME.txt
41 lines (29 loc) · 1.3 KB
/
READ ME.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--------------------------
The shopping cart scenario
--------------------------
You must build a simple shopping cart API, in which you can add products + how many of them you want.
Based on how many of the products you add to the cart, the calculated price may fall into a 'discount tier'.
For example you have a product called 'Orange', it costs £0.20 each for the first 20,
£0.18 for the next 80 and after 100 it will cost £0.12 each.
For this example we'll have the following products:
Lemon:
0-10 = £0.50
10+ = £0.45
Tomato:
0-20 = £0.20
21-100 = £0.18
100+ = £0.14
The goal of this test is to write a script using the interface for the shopping cart we provided
(the rest of the implementation is completely up to you) that prints output in the following way:
8 Lemon £4.00
25 Tomato £4.90
-----------------
Total: £8.90
Spacing is dynamically generated depending on product name, so say 'Lemon' would be changed into 'Green Grape',
the spacing for previous and next rows would be adjusted so that the pricing is still in line across all rows.
So to clarify...
$cart->addItem($lemon, 10); // Amount of lemons in cart is now 10
echo $cart->getPriceOf($lemon); // 0.50
$cart->addItem($lemon, 5); // Amount of lemons in cart is now 15
echo $cart->getPriceOf($lemon); // 0.45
echo $cart->getTotalSum(); // Final output