diff --git a/src/data/Cart.java b/src/data/Cart.java index 9d20bc3..bfb7cf3 100644 --- a/src/data/Cart.java +++ b/src/data/Cart.java @@ -1,5 +1,7 @@ package estore.services.implem.src.data; +import estore.services.implem.src.services.Client; + import java.util.HashMap; import java.util.Map; diff --git a/src/data/Order.java b/src/data/Order.java index 66e24b7..c70f221 100644 --- a/src/data/Order.java +++ b/src/data/Order.java @@ -3,10 +3,10 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Set; +import estore.services.implem.src.services.Client; import estorePojo.exceptions.UnknownItemException; public class Order { diff --git a/src/main/Main.java b/src/main/Main.java index 96907b2..0d9fea4 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -1,7 +1,7 @@ package main; import estore.services.implem.src.services.Bank; -import estore.services.implem.src.data.Client; +import estore.services.implem.src.services.Client; import estore.services.implem.src.services.Provider; import estore.services.implem.src.services.Store; diff --git a/src/data/Client.java b/src/services/Client.java similarity index 95% rename from src/data/Client.java rename to src/services/Client.java index 8874237..14c0c48 100644 --- a/src/data/Client.java +++ b/src/services/Client.java @@ -1,86 +1,88 @@ -package estore.services.implem.src.data; - -import estorePojo.exceptions.InsufficientBalanceException; -import estorePojo.exceptions.InvalidCartException; -import estorePojo.exceptions.UnknownAccountException; -import estorePojo.exceptions.UnknownItemException; - -public class Client implements Runnable { - - private Store store; - - public Client (Store s){ - store = s; - } - // ----------------------------------------------------- - // Implementation of the Runnable interface - // ----------------------------------------------------- - - public void run() { - - // Scenario 1 - // Direct ordering of an item - // The scenario is run twice - System.out.println("Scenario 1"); - scenario1("CD",2,"Lille","Bob"); - scenario1("CD",1,"Lille","Anne"); - System.out.println(); - - // Scenario 2 - // Ordering of several items by using a cart - System.out.println("Scenario 2"); - scenario2(new String[]{"DVD","CD"},new int[]{2,1},"Lille","Bob"); - System.out.println(); - } - - private void scenario1( - String item, int qty, String address, String account ) { - - try { - _scenario1(item,qty,address,account); - } - catch (Exception e) { - System.err.println("Exception: "+e.getMessage()); - e.printStackTrace(); - } - } - - private void _scenario1( - String item, int qty, String address, String account ) - throws - UnknownItemException, - InsufficientBalanceException, UnknownAccountException{ - - System.out.println("Ordering "+qty+" "+item+" for "+account+"..."); - Order order = store.oneShotOrder(this,item,qty,address,account); - System.out.println(order); - } - - private void scenario2( - String[] items, int[] qties, String address, String account ) { - - try { - _scenario2(items,qties,address,account); - } - catch (Exception e) { - System.err.println("Exception: "+e.getMessage()); - e.printStackTrace(); - } - } - - private void _scenario2( - String[] items, int[] qties, String address, String account ) - throws - InsufficientBalanceException, UnknownAccountException, - UnknownItemException, InvalidCartException{ - - System.out.println("Ordering for "+account+"..."); - Cart cart = null; - for (int i = 0; i < items.length; i++) { - System.out.println("Item: "+items[i]+", quantity: "+qties[i]); - cart = store.addItemToCart(cart,this,items[i],qties[i]); - } - Order order = store.pay(cart,address,account); - System.out.println(order); - } -} +package estore.services.implem.src.services; + +import estore.services.implem.src.data.Cart; +import estore.services.implem.src.data.Order; +import estorePojo.exceptions.InsufficientBalanceException; +import estorePojo.exceptions.InvalidCartException; +import estorePojo.exceptions.UnknownAccountException; +import estorePojo.exceptions.UnknownItemException; + +public class Client implements Runnable { + + private Store store; + + public Client (Store s){ + store = s; + } + // ----------------------------------------------------- + // Implementation of the Runnable interface + // ----------------------------------------------------- + + public void run() { + + // Scenario 1 + // Direct ordering of an item + // The scenario is run twice + System.out.println("Scenario 1"); + scenario1("CD",2,"Lille","Bob"); + scenario1("CD",1,"Lille","Anne"); + System.out.println(); + + // Scenario 2 + // Ordering of several items by using a cart + System.out.println("Scenario 2"); + scenario2(new String[]{"DVD","CD"},new int[]{2,1},"Lille","Bob"); + System.out.println(); + } + + private void scenario1( + String item, int qty, String address, String account ) { + + try { + _scenario1(item,qty,address,account); + } + catch (Exception e) { + System.err.println("Exception: "+e.getMessage()); + e.printStackTrace(); + } + } + + private void _scenario1( + String item, int qty, String address, String account ) + throws + UnknownItemException, + InsufficientBalanceException, UnknownAccountException{ + + System.out.println("Ordering "+qty+" "+item+" for "+account+"..."); + Order order = store.oneShotOrder(this,item,qty,address,account); + System.out.println(order); + } + + private void scenario2( + String[] items, int[] qties, String address, String account ) { + + try { + _scenario2(items,qties,address,account); + } + catch (Exception e) { + System.err.println("Exception: "+e.getMessage()); + e.printStackTrace(); + } + } + + private void _scenario2( + String[] items, int[] qties, String address, String account ) + throws + InsufficientBalanceException, UnknownAccountException, + UnknownItemException, InvalidCartException{ + + System.out.println("Ordering for "+account+"..."); + Cart cart = null; + for (int i = 0; i < items.length; i++) { + System.out.println("Item: "+items[i]+", quantity: "+qties[i]); + cart = store.addItemToCart(cart,this,items[i],qties[i]); + } + Order order = store.pay(cart,address,account); + System.out.println(order); + } +} diff --git a/src/services/Provider.java b/src/services/Provider.java index a1e1765..63c20fa 100644 --- a/src/services/Provider.java +++ b/src/services/Provider.java @@ -29,7 +29,7 @@ public double getPrice(Object item) throws UnknownItemException { if (!itemPrices.containsKey(item)) throw new UnknownItemException("Item " + item + " is not an item delivered by this provider."); - Double price = (Double) itemPrices.get(item); + Double price = (Double) itemPlrices.get(item); return price.doubleValue(); }