Skip to content

Commit

Permalink
Fix commit : Differentiate data and services type
Browse files Browse the repository at this point in the history
  • Loading branch information
Penepou committed Jan 19, 2024
1 parent 294b46a commit 9de36b0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 89 deletions.
2 changes: 2 additions & 0 deletions src/data/Cart.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/data/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/Main.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
174 changes: 88 additions & 86 deletions src/data/Client.java → src/services/Client.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion src/services/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 9de36b0

Please sign in to comment.