File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ package io .shodo ;
2+
3+ import java .util .HashMap ;
4+
5+ /**
6+ * Created by thomas on 02/12/2019.
7+ * This class is a basket
8+ */
9+ public class BasketInformations {
10+
11+ // The product of the basket
12+ static HashMap <String , Integer > map = new HashMap <String , Integer >();
13+
14+ // The fact that the basket has gift card
15+ private static boolean giftCard = false ;
16+
17+ public void addProductToBasket (String product , Integer price , boolean isGiftCard ) {
18+ if (isGiftCard ) {
19+ giftCard = true ;
20+ } else {
21+ map .put (product , price );
22+ }
23+ }
24+
25+ public Long getBasketPrice (boolean inCents ) {
26+ Integer v = 0 ;
27+ for (String s : map .keySet ()) {
28+ v += map .get (s );
29+ }
30+ if (giftCard ) {
31+ v += 100 ;
32+ }
33+ return inCents ? v * 100 : Long .valueOf (v );
34+ }
35+
36+ public void resetBasket () {
37+ buyBasket ();
38+ giftCard = false ;
39+ }
40+
41+ public void buyBasket () {
42+ map .clear ();
43+ }
44+
45+ public boolean isBasketContains (String produit ) {
46+ boolean found = false ;
47+ for (String s : map .keySet ()) {
48+ if (s == produit ) found = true ;
49+ }
50+ return found ;
51+ }
52+
53+ public void mixWithCocktail (BasketInformations b ) {
54+ map .putAll (b .map );
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments