From 619faafec16315620086156db7f2d9dd3c105dd7 Mon Sep 17 00:00:00 2001 From: aleseyko Date: Mon, 4 Mar 2019 17:37:51 +0200 Subject: [PATCH 1/9] transfer implementation to specific classes --- oop-workshop.iml | 22 ++++++++++++++++++++++ src/checkout/AnyGoodsOffer.java | 3 ++- src/checkout/CheckoutService.java | 11 ----------- src/checkout/FactorByCategoryOffer.java | 3 ++- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/oop-workshop.iml b/oop-workshop.iml index f6a7637..678d355 100644 --- a/oop-workshop.iml +++ b/oop-workshop.iml @@ -21,5 +21,27 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/checkout/AnyGoodsOffer.java b/src/checkout/AnyGoodsOffer.java index 8b11348..b876763 100644 --- a/src/checkout/AnyGoodsOffer.java +++ b/src/checkout/AnyGoodsOffer.java @@ -11,6 +11,7 @@ public AnyGoodsOffer(int totalCost, int points) { @Override public void apply(Check check) { - + if (totalCost <= check.getTotalCost()) + check.addPoints(points); } } diff --git a/src/checkout/CheckoutService.java b/src/checkout/CheckoutService.java index 3ac7cbb..72e9a53 100644 --- a/src/checkout/CheckoutService.java +++ b/src/checkout/CheckoutService.java @@ -23,16 +23,5 @@ public Check closeCheck() { public void useOffer(Offer offer) { offer.apply(check); - if (offer instanceof FactorByCategoryOffer) { - FactorByCategoryOffer fbOffer = (FactorByCategoryOffer) offer; - int points = check.getCostByCategory(fbOffer.category); - check.addPoints(points * (fbOffer.factor - 1)); - } else { - if (offer instanceof AnyGoodsOffer) { - AnyGoodsOffer agOffer = (AnyGoodsOffer) offer; - if (agOffer.totalCost <= check.getTotalCost()) - check.addPoints(agOffer.points); - } - } } } diff --git a/src/checkout/FactorByCategoryOffer.java b/src/checkout/FactorByCategoryOffer.java index fee57f0..f10f681 100644 --- a/src/checkout/FactorByCategoryOffer.java +++ b/src/checkout/FactorByCategoryOffer.java @@ -11,6 +11,7 @@ public FactorByCategoryOffer(Category category, int factor) { @Override public void apply(Check check) { - + int points = check.getCostByCategory(category); + check.addPoints(points * (factor - 1)); } } From fe21097599efce6874278d8b5a4d20e6d0b2f9f2 Mon Sep 17 00:00:00 2001 From: aleseyko Date: Mon, 4 Mar 2019 17:55:47 +0200 Subject: [PATCH 2/9] added ability to use offers before closing a check --- src/checkout/CheckoutService.java | 9 ++++++++- test/CheckoutServiceTest.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/checkout/CheckoutService.java b/src/checkout/CheckoutService.java index 72e9a53..e5ec83b 100644 --- a/src/checkout/CheckoutService.java +++ b/src/checkout/CheckoutService.java @@ -1,8 +1,12 @@ package checkout; +import java.util.ArrayList; +import java.util.List; + public class CheckoutService { private Check check; + private List offers = new ArrayList<>(); public void openCheck() { check = new Check(); @@ -17,11 +21,14 @@ public void addProduct(Product product) { public Check closeCheck() { Check closedCheck = check; + for (Offer offer: offers) { + offer.apply(check); + } check = null; return closedCheck; } public void useOffer(Offer offer) { - offer.apply(check); + offers.add(offer); } } diff --git a/test/CheckoutServiceTest.java b/test/CheckoutServiceTest.java index a34315e..23b6ef0 100644 --- a/test/CheckoutServiceTest.java +++ b/test/CheckoutServiceTest.java @@ -89,4 +89,15 @@ void useOffer__factorByCategory() { assertThat(check.getTotalPoints(), is(31)); } + + @Test + void addProducts__afterUseOffers(){ + checkoutService.addProduct(milk_7); + checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2)); + checkoutService.addProduct(milk_7); + checkoutService.addProduct(bred_3); + Check check = checkoutService.closeCheck(); + + assertThat(check.getTotalPoints(), is(31)); + } } From cbce6c668fb81abb493bff193ca4b94f216efb14 Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Tue, 5 Mar 2019 10:48:59 +0200 Subject: [PATCH 3/9] added expiry time of offers --- src/checkout/AnyGoodsOffer.java | 7 +++++-- src/checkout/Check.java | 11 +++++++++++ src/checkout/CheckoutService.java | 7 ++----- src/checkout/FactorByCategoryOffer.java | 8 +++++--- src/checkout/Offer.java | 14 +++++++++++++- test/CheckoutServiceTest.java | 20 ++++++++++++++++---- 6 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/checkout/AnyGoodsOffer.java b/src/checkout/AnyGoodsOffer.java index b876763..6d2a858 100644 --- a/src/checkout/AnyGoodsOffer.java +++ b/src/checkout/AnyGoodsOffer.java @@ -1,16 +1,19 @@ package checkout; +import java.time.LocalDate; + public class AnyGoodsOffer extends Offer { public final int totalCost; public final int points; - public AnyGoodsOffer(int totalCost, int points) { + public AnyGoodsOffer(int totalCost, int points, LocalDate expiredDate) { + super(expiredDate); this.totalCost = totalCost; this.points = points; } @Override - public void apply(Check check) { + public void applyAfterCheck(Check check) { if (totalCost <= check.getTotalCost()) check.addPoints(points); } diff --git a/src/checkout/Check.java b/src/checkout/Check.java index 31436e5..79ad2a6 100644 --- a/src/checkout/Check.java +++ b/src/checkout/Check.java @@ -5,6 +5,7 @@ public class Check { private List products = new ArrayList<>(); + private List offers = new ArrayList<>(); private int points = 0; public int getTotalCost() { @@ -27,6 +28,16 @@ void addPoints(int points) { this.points += points; } + void useOffers(Check check) { + for (Offer offer: offers) { + offer.apply(check); + } + } + + void addOffer(Offer offer) { + offers.add(offer); + } + int getCostByCategory(Category category) { return products.stream() .filter(p -> p.category == category) diff --git a/src/checkout/CheckoutService.java b/src/checkout/CheckoutService.java index e5ec83b..eabaa58 100644 --- a/src/checkout/CheckoutService.java +++ b/src/checkout/CheckoutService.java @@ -6,7 +6,6 @@ public class CheckoutService { private Check check; - private List offers = new ArrayList<>(); public void openCheck() { check = new Check(); @@ -20,15 +19,13 @@ public void addProduct(Product product) { } public Check closeCheck() { + check.useOffers(check); Check closedCheck = check; - for (Offer offer: offers) { - offer.apply(check); - } check = null; return closedCheck; } public void useOffer(Offer offer) { - offers.add(offer); + check.addOffer(offer); } } diff --git a/src/checkout/FactorByCategoryOffer.java b/src/checkout/FactorByCategoryOffer.java index f10f681..ddccabb 100644 --- a/src/checkout/FactorByCategoryOffer.java +++ b/src/checkout/FactorByCategoryOffer.java @@ -1,16 +1,18 @@ package checkout; +import java.time.LocalDate; + public class FactorByCategoryOffer extends Offer { final Category category; final int factor; - public FactorByCategoryOffer(Category category, int factor) { + public FactorByCategoryOffer(Category category, int factor, LocalDate expiredDate) { + super(expiredDate); this.category = category; this.factor = factor; } - @Override - public void apply(Check check) { + public void applyAfterCheck(Check check) { int points = check.getCostByCategory(category); check.addPoints(points * (factor - 1)); } diff --git a/src/checkout/Offer.java b/src/checkout/Offer.java index f2c67fe..2cb7e20 100644 --- a/src/checkout/Offer.java +++ b/src/checkout/Offer.java @@ -1,5 +1,17 @@ package checkout; +import java.time.LocalDate; + public abstract class Offer { - public abstract void apply(Check check); + private LocalDate expiredDate; + + public Offer(LocalDate expiredDate) { + this.expiredDate = expiredDate; + } + public abstract void applyAfterCheck(Check check); + public void apply(Check check) { + if(expiredDate.isAfter(LocalDate.now())){ + applyAfterCheck(check); + } + } } diff --git a/test/CheckoutServiceTest.java b/test/CheckoutServiceTest.java index 23b6ef0..b9c0d88 100644 --- a/test/CheckoutServiceTest.java +++ b/test/CheckoutServiceTest.java @@ -2,6 +2,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.time.LocalDate; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -10,6 +12,7 @@ public class CheckoutServiceTest { private Product milk_7; private CheckoutService checkoutService; private Product bred_3; + private LocalDate expiredDate = LocalDate.of(2100, 4, 14); @BeforeEach void setUp() { @@ -62,7 +65,7 @@ void useOffer__addOfferPoints() { checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); - checkoutService.useOffer(new AnyGoodsOffer(6, 2)); + checkoutService.useOffer(new AnyGoodsOffer(6, 2, expiredDate)); Check check = checkoutService.closeCheck(); assertThat(check.getTotalPoints(), is(12)); @@ -72,7 +75,7 @@ void useOffer__addOfferPoints() { void useOffer__whenCostLessThanRequired__doNothing() { checkoutService.addProduct(bred_3); - checkoutService.useOffer(new AnyGoodsOffer(6, 2)); + checkoutService.useOffer(new AnyGoodsOffer(6, 2, expiredDate)); Check check = checkoutService.closeCheck(); assertThat(check.getTotalPoints(), is(3)); @@ -84,7 +87,7 @@ void useOffer__factorByCategory() { checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); - checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2)); + checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2, expiredDate)); Check check = checkoutService.closeCheck(); assertThat(check.getTotalPoints(), is(31)); @@ -93,11 +96,20 @@ void useOffer__factorByCategory() { @Test void addProducts__afterUseOffers(){ checkoutService.addProduct(milk_7); - checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2)); + checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2, expiredDate)); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); assertThat(check.getTotalPoints(), is(31)); } + + @Test + void useExpiredOffer() { + checkoutService.addProduct(milk_7); + checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 7, LocalDate.of(2008, 7, 5))); + Check check = checkoutService.closeCheck(); + assertThat(check.getTotalPoints(), is(7)); + } } + From 4d8aebe7d25fac747787d00c5f0a614c5863b078 Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Tue, 5 Mar 2019 11:46:05 +0200 Subject: [PATCH 4/9] add discount offer --- src/checkout/Check.java | 21 +++++++++++++++------ src/checkout/DiscountByCategoryOffer.java | 20 ++++++++++++++++++++ test/CheckoutServiceTest.java | 15 +++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/checkout/DiscountByCategoryOffer.java diff --git a/src/checkout/Check.java b/src/checkout/Check.java index 79ad2a6..c36c34f 100644 --- a/src/checkout/Check.java +++ b/src/checkout/Check.java @@ -7,21 +7,26 @@ public class Check { private List products = new ArrayList<>(); private List offers = new ArrayList<>(); private int points = 0; - - public int getTotalCost() { - int totalCost = 0; + private double discount = 0; + public int getTotalPrice() { + int totalPrice = 0; for (Product product : this.products) { - totalCost += product.price; + totalPrice += product.price; } + return totalPrice; + } + public double getTotalCost() { + double totalCost = 0; + totalCost += getTotalPrice(); + totalCost -= discount; return totalCost; } - void addProduct(Product product) { products.add(product); } public int getTotalPoints() { - return getTotalCost() + points; + return getTotalPrice() + points; } void addPoints(int points) { @@ -44,4 +49,8 @@ int getCostByCategory(Category category) { .mapToInt(p -> p.price) .reduce(0, (a, b) -> a + b); } + + void addDiscount(double discount) { + this.discount += discount; + } } diff --git a/src/checkout/DiscountByCategoryOffer.java b/src/checkout/DiscountByCategoryOffer.java new file mode 100644 index 0000000..67bdb9e --- /dev/null +++ b/src/checkout/DiscountByCategoryOffer.java @@ -0,0 +1,20 @@ +package checkout; + + +import java.time.LocalDate; + +public class DiscountByCategoryOffer extends Offer { + Category category; + int discount; + public DiscountByCategoryOffer(Category category, int discount, LocalDate expiredDate) { + super(expiredDate); + this.category = category; + this.discount = discount; + } + + @Override + public void applyAfterCheck(Check check) { + double cost = check.getCostByCategory(category); + check.addDiscount(cost*discount/100); + } +} diff --git a/test/CheckoutServiceTest.java b/test/CheckoutServiceTest.java index b9c0d88..b158f6b 100644 --- a/test/CheckoutServiceTest.java +++ b/test/CheckoutServiceTest.java @@ -28,7 +28,7 @@ void closeCheck__withOneProduct() { checkoutService.addProduct(milk_7); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalCost(), is(7)); + assertThat(check.getTotalCost(), is(7.0)); } @Test @@ -37,18 +37,18 @@ void closeCheck__withTwoProducts() { checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalCost(), is(10)); + assertThat(check.getTotalCost(), is(10.0)); } @Test void addProduct__whenCheckIsClosed__opensNewCheck() { checkoutService.addProduct(milk_7); Check milkCheck = checkoutService.closeCheck(); - assertThat(milkCheck.getTotalCost(), is(7)); + assertThat(milkCheck.getTotalCost(), is(7.0)); checkoutService.addProduct(bred_3); Check bredCheck = checkoutService.closeCheck(); - assertThat(bredCheck.getTotalCost(), is(3)); + assertThat(bredCheck.getTotalCost(), is(3.0)); } @Test @@ -111,5 +111,12 @@ void useExpiredOffer() { Check check = checkoutService.closeCheck(); assertThat(check.getTotalPoints(), is(7)); } + @Test + void useDiscountOffer() { + checkoutService.addProduct(milk_7); + checkoutService.useOffer(new DiscountByCategoryOffer(Category.MILK, 50, expiredDate)); + Check check = checkoutService.closeCheck(); + assertThat(check.getTotalCost(), is(3.5)); + } } From 6b8cffb55d43fdf73f30f7bdd41037f21ff142d3 Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Tue, 5 Mar 2019 14:55:58 +0200 Subject: [PATCH 5/9] use strategy design pattern for reward and condition combining --- src/checkout/AnyGoodsOffer.java | 20 ------ src/checkout/Category.java | 3 +- src/checkout/Check.java | 7 +++ src/checkout/Condition.java | 7 +++ src/checkout/ConditionByCategory.java | 22 +++++++ src/checkout/ConditionByOutlet.java | 22 +++++++ src/checkout/ConditionOfTotalCost.java | 19 ++++++ src/checkout/DiscountByCategoryOffer.java | 20 ------ src/checkout/DiscountReward.java | 12 ++++ src/checkout/FactorByCategoryOffer.java | 19 ------ src/checkout/FactorReward.java | 12 ++++ src/checkout/FlatReward.java | 13 ++++ src/checkout/Offer.java | 15 +++-- src/checkout/Outlet.java | 7 +++ src/checkout/Product.java | 6 +- src/checkout/Reward.java | 5 ++ test/CheckoutServiceTest.java | 77 ++++++++++------------- 17 files changed, 175 insertions(+), 111 deletions(-) delete mode 100644 src/checkout/AnyGoodsOffer.java create mode 100644 src/checkout/Condition.java create mode 100644 src/checkout/ConditionByCategory.java create mode 100644 src/checkout/ConditionByOutlet.java create mode 100644 src/checkout/ConditionOfTotalCost.java delete mode 100644 src/checkout/DiscountByCategoryOffer.java create mode 100644 src/checkout/DiscountReward.java delete mode 100644 src/checkout/FactorByCategoryOffer.java create mode 100644 src/checkout/FactorReward.java create mode 100644 src/checkout/FlatReward.java create mode 100644 src/checkout/Outlet.java create mode 100644 src/checkout/Reward.java diff --git a/src/checkout/AnyGoodsOffer.java b/src/checkout/AnyGoodsOffer.java deleted file mode 100644 index 6d2a858..0000000 --- a/src/checkout/AnyGoodsOffer.java +++ /dev/null @@ -1,20 +0,0 @@ -package checkout; - -import java.time.LocalDate; - -public class AnyGoodsOffer extends Offer { - public final int totalCost; - public final int points; - - public AnyGoodsOffer(int totalCost, int points, LocalDate expiredDate) { - super(expiredDate); - this.totalCost = totalCost; - this.points = points; - } - - @Override - public void applyAfterCheck(Check check) { - if (totalCost <= check.getTotalCost()) - check.addPoints(points); - } -} diff --git a/src/checkout/Category.java b/src/checkout/Category.java index 0f1dff7..6345bb9 100644 --- a/src/checkout/Category.java +++ b/src/checkout/Category.java @@ -1,5 +1,6 @@ package checkout; public enum Category { - MILK + MILK, + BRED } diff --git a/src/checkout/Check.java b/src/checkout/Check.java index c36c34f..10f779a 100644 --- a/src/checkout/Check.java +++ b/src/checkout/Check.java @@ -50,6 +50,13 @@ int getCostByCategory(Category category) { .reduce(0, (a, b) -> a + b); } + int getCostByOutlet(Outlet outlet) { + return products.stream() + .filter(p -> p.outlet == outlet) + .mapToInt(p -> p.price) + .reduce(0, (a,b) -> a + b); + } + void addDiscount(double discount) { this.discount += discount; } diff --git a/src/checkout/Condition.java b/src/checkout/Condition.java new file mode 100644 index 0000000..8d125ae --- /dev/null +++ b/src/checkout/Condition.java @@ -0,0 +1,7 @@ +package checkout; + +public interface Condition { + boolean checkCondition(Check check); + + int getCostForCondition(Check check); +} diff --git a/src/checkout/ConditionByCategory.java b/src/checkout/ConditionByCategory.java new file mode 100644 index 0000000..371ad99 --- /dev/null +++ b/src/checkout/ConditionByCategory.java @@ -0,0 +1,22 @@ +package checkout; + +public class ConditionByCategory implements Condition { + Category category; + public ConditionByCategory(Category category) { + this.category = category; + } + + @Override + public boolean checkCondition(Check check) { + if(check.getCostByCategory(category) != 0){ + return true; + }else{ + return false; + } + } + + @Override + public int getCostForCondition(Check check) { + return check.getCostByCategory(category); + } +} diff --git a/src/checkout/ConditionByOutlet.java b/src/checkout/ConditionByOutlet.java new file mode 100644 index 0000000..8fb5ace --- /dev/null +++ b/src/checkout/ConditionByOutlet.java @@ -0,0 +1,22 @@ +package checkout; + +public class ConditionByOutlet implements Condition { + Outlet outlet; + public ConditionByOutlet(Outlet outlet) { + this.outlet = outlet; + } + + @Override + public boolean checkCondition(Check check) { + if(check.getCostByOutlet(outlet) != 0){ + return true; + }else{ + return false; + } + } + + @Override + public int getCostForCondition(Check check) { + return check.getCostByOutlet(outlet); + } +} diff --git a/src/checkout/ConditionOfTotalCost.java b/src/checkout/ConditionOfTotalCost.java new file mode 100644 index 0000000..b6900f6 --- /dev/null +++ b/src/checkout/ConditionOfTotalCost.java @@ -0,0 +1,19 @@ +package checkout; + +public class ConditionOfTotalCost implements Condition { + int totalCost; + public ConditionOfTotalCost(int totalCost) { + this.totalCost = totalCost; + } + + public boolean checkCondition(Check check) { + if (check.getTotalCost() < totalCost) { + return false; + }else{ + return true; + } + } + public int getCostForCondition(Check check) { + return check.getTotalPrice(); + } +} diff --git a/src/checkout/DiscountByCategoryOffer.java b/src/checkout/DiscountByCategoryOffer.java deleted file mode 100644 index 67bdb9e..0000000 --- a/src/checkout/DiscountByCategoryOffer.java +++ /dev/null @@ -1,20 +0,0 @@ -package checkout; - - -import java.time.LocalDate; - -public class DiscountByCategoryOffer extends Offer { - Category category; - int discount; - public DiscountByCategoryOffer(Category category, int discount, LocalDate expiredDate) { - super(expiredDate); - this.category = category; - this.discount = discount; - } - - @Override - public void applyAfterCheck(Check check) { - double cost = check.getCostByCategory(category); - check.addDiscount(cost*discount/100); - } -} diff --git a/src/checkout/DiscountReward.java b/src/checkout/DiscountReward.java new file mode 100644 index 0000000..1bb6103 --- /dev/null +++ b/src/checkout/DiscountReward.java @@ -0,0 +1,12 @@ +package checkout; + +public class DiscountReward implements Reward{ + int discount; + public DiscountReward(int discount) { + this.discount = discount; + } + + public void applyReward(Check check, int cost){ + check.addDiscount(cost*discount/100.0); + } +} diff --git a/src/checkout/FactorByCategoryOffer.java b/src/checkout/FactorByCategoryOffer.java deleted file mode 100644 index ddccabb..0000000 --- a/src/checkout/FactorByCategoryOffer.java +++ /dev/null @@ -1,19 +0,0 @@ -package checkout; - -import java.time.LocalDate; - -public class FactorByCategoryOffer extends Offer { - final Category category; - final int factor; - - public FactorByCategoryOffer(Category category, int factor, LocalDate expiredDate) { - super(expiredDate); - this.category = category; - this.factor = factor; - } - @Override - public void applyAfterCheck(Check check) { - int points = check.getCostByCategory(category); - check.addPoints(points * (factor - 1)); - } -} diff --git a/src/checkout/FactorReward.java b/src/checkout/FactorReward.java new file mode 100644 index 0000000..d8aa095 --- /dev/null +++ b/src/checkout/FactorReward.java @@ -0,0 +1,12 @@ +package checkout; + +public class FactorReward implements Reward { + int factor; + public FactorReward(int factor) { + this.factor = factor; + } + + public void applyReward(Check check, int cost){ + check.addPoints(cost*(factor-1)); + } +} diff --git a/src/checkout/FlatReward.java b/src/checkout/FlatReward.java new file mode 100644 index 0000000..3d99c45 --- /dev/null +++ b/src/checkout/FlatReward.java @@ -0,0 +1,13 @@ +package checkout; + +public class FlatReward implements Reward{ + int flat; + public FlatReward(int flat) { + this.flat = flat; + } + + public void applyReward(Check check, int cost){ + check.addPoints(flat); + } +} + diff --git a/src/checkout/Offer.java b/src/checkout/Offer.java index 2cb7e20..33db77e 100644 --- a/src/checkout/Offer.java +++ b/src/checkout/Offer.java @@ -2,16 +2,21 @@ import java.time.LocalDate; -public abstract class Offer { +public class Offer { private LocalDate expiredDate; + private Reward rewardType; + private Condition conditionType; - public Offer(LocalDate expiredDate) { + + public Offer(LocalDate expiredDate, Reward rewardType, Condition conditionType) { this.expiredDate = expiredDate; + this.rewardType = rewardType; + this.conditionType = conditionType; } - public abstract void applyAfterCheck(Check check); + public void apply(Check check) { - if(expiredDate.isAfter(LocalDate.now())){ - applyAfterCheck(check); + if(expiredDate.isAfter(LocalDate.now()) && conditionType.checkCondition(check)){ + rewardType.applyReward(check, conditionType.getCostForCondition(check)); } } } diff --git a/src/checkout/Outlet.java b/src/checkout/Outlet.java new file mode 100644 index 0000000..fd427ca --- /dev/null +++ b/src/checkout/Outlet.java @@ -0,0 +1,7 @@ +package checkout; + +public enum Outlet { + PEPSI, + ROSHEN, + LAYS +} diff --git a/src/checkout/Product.java b/src/checkout/Product.java index f03a6e8..84093c4 100644 --- a/src/checkout/Product.java +++ b/src/checkout/Product.java @@ -4,14 +4,16 @@ public class Product { final int price; final String name; Category category; + Outlet outlet; - public Product(int price, String name, Category category) { + public Product(int price, String name, Category category, Outlet outlet) { this.price = price; this.name = name; this.category = category; + this.outlet = outlet; } public Product(int price, String name) { - this(price, name, null); + this(price, name, null, null); } } diff --git a/src/checkout/Reward.java b/src/checkout/Reward.java new file mode 100644 index 0000000..22b23c5 --- /dev/null +++ b/src/checkout/Reward.java @@ -0,0 +1,5 @@ +package checkout; + +public interface Reward { + void applyReward(Check check, int cost) ; +} diff --git a/test/CheckoutServiceTest.java b/test/CheckoutServiceTest.java index b158f6b..9775d5b 100644 --- a/test/CheckoutServiceTest.java +++ b/test/CheckoutServiceTest.java @@ -1,6 +1,7 @@ import checkout.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import sun.security.x509.CertAttrSet; import java.time.LocalDate; @@ -19,104 +20,92 @@ void setUp() { checkoutService = new CheckoutService(); checkoutService.openCheck(); - milk_7 = new Product(7, "Milk", Category.MILK); - bred_3 = new Product(3, "Bred"); + milk_7 = new Product(7, "Milk", Category.MILK, Outlet.PEPSI); + bred_3 = new Product(3, "Bred", Category.BRED, Outlet.ROSHEN); } @Test - void closeCheck__withOneProduct() { + void useFactorReward_whenCostMoreThenRequired() { checkoutService.addProduct(milk_7); + checkoutService.useOffer(new Offer(expiredDate, new FactorReward(3), new ConditionOfTotalCost(10))); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalCost(), is(7.0)); + assertThat(check.getTotalPoints(), is(7)); } @Test - void closeCheck__withTwoProducts() { + void useFactorRewardAndConditionByCategory() { + checkoutService.addProduct(milk_7); + checkoutService.useOffer(new Offer(expiredDate, new FactorReward(3), new ConditionByCategory(Category.MILK))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalCost(), is(10.0)); + assertThat(check.getTotalPoints(), is(45)); } @Test - void addProduct__whenCheckIsClosed__opensNewCheck() { + void useFlatRewardAndConditionByCategory() { checkoutService.addProduct(milk_7); - Check milkCheck = checkoutService.closeCheck(); - assertThat(milkCheck.getTotalCost(), is(7.0)); - - checkoutService.addProduct(bred_3); - Check bredCheck = checkoutService.closeCheck(); - assertThat(bredCheck.getTotalCost(), is(3.0)); - } - - @Test - void closeCheck__calcTotalPoints() { + checkoutService.useOffer(new Offer(expiredDate, new FlatReward(100), new ConditionByCategory(Category.MILK))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(10)); + assertThat(check.getTotalPoints(), is(117)); } - @Test - void useOffer__addOfferPoints() { + void useFlatRewardAndConditionByOutlet() { + checkoutService.addProduct(milk_7); + checkoutService.useOffer(new Offer(expiredDate, new FlatReward(30), new ConditionByOutlet(Outlet.ROSHEN))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); - - checkoutService.useOffer(new AnyGoodsOffer(6, 2, expiredDate)); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(12)); + assertThat(check.getTotalPoints(), is(47)); } - @Test - void useOffer__whenCostLessThanRequired__doNothing() { + void useDiscountRewardAndConditionByOutlet() { + checkoutService.addProduct(milk_7); + checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionByOutlet(Outlet.ROSHEN))); + checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); - - checkoutService.useOffer(new AnyGoodsOffer(6, 2, expiredDate)); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(3)); + assertThat(check.getTotalCost(), is(15.5)); } @Test - void useOffer__factorByCategory() { + void useDiscountRewardAndConditionByOutlet__whenOutletNotFound() { checkoutService.addProduct(milk_7); + checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionByOutlet(Outlet.LAYS))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); - - checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2, expiredDate)); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(31)); + assertThat(check.getTotalCost(), is(17.0)); } @Test - void addProducts__afterUseOffers(){ + void useDiscountRewardAndConditionByTotalCost() { checkoutService.addProduct(milk_7); - checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 2, expiredDate)); + checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionOfTotalCost(7))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(31)); + assertThat(check.getTotalCost(), is(8.5)); } @Test - void useExpiredOffer() { + void useDiscountRewardAndConditionByTotalCost__whenTotalCostLessThenRequire() { checkoutService.addProduct(milk_7); - checkoutService.useOffer(new FactorByCategoryOffer(Category.MILK, 7, LocalDate.of(2008, 7, 5))); - Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(7)); - } - @Test - void useDiscountOffer() { + checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionOfTotalCost(50))); checkoutService.addProduct(milk_7); - checkoutService.useOffer(new DiscountByCategoryOffer(Category.MILK, 50, expiredDate)); + checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalCost(), is(3.5)); + + assertThat(check.getTotalCost(), is(17.0)); } } From 5603fc4f1eb5a229ef91d8ebf03bef7af372c6be Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Wed, 6 Mar 2019 09:21:07 +0200 Subject: [PATCH 6/9] add check amount to condition by category and by trade mark, and refactor code --- src/checkout/Check.java | 13 +++---------- src/checkout/CheckoutService.java | 3 --- src/checkout/ConditionByCategory.java | 19 ++++++++++++------ src/checkout/ConditionByOutlet.java | 22 --------------------- src/checkout/ConditionByTradeMark.java | 27 ++++++++++++++++++++++++++ src/checkout/ConditionOfTotalCost.java | 6 +----- test/CheckoutServiceTest.java | 17 ++++++++-------- 7 files changed, 53 insertions(+), 54 deletions(-) delete mode 100644 src/checkout/ConditionByOutlet.java create mode 100644 src/checkout/ConditionByTradeMark.java diff --git a/src/checkout/Check.java b/src/checkout/Check.java index 10f779a..28ae1fe 100644 --- a/src/checkout/Check.java +++ b/src/checkout/Check.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; public class Check { private List products = new ArrayList<>(); @@ -43,20 +44,12 @@ void addOffer(Offer offer) { offers.add(offer); } - int getCostByCategory(Category category) { + int getSubCost(Predicate predicate) { return products.stream() - .filter(p -> p.category == category) - .mapToInt(p -> p.price) - .reduce(0, (a, b) -> a + b); - } - - int getCostByOutlet(Outlet outlet) { - return products.stream() - .filter(p -> p.outlet == outlet) + .filter(predicate) .mapToInt(p -> p.price) .reduce(0, (a,b) -> a + b); } - void addDiscount(double discount) { this.discount += discount; } diff --git a/src/checkout/CheckoutService.java b/src/checkout/CheckoutService.java index eabaa58..d0b8bcb 100644 --- a/src/checkout/CheckoutService.java +++ b/src/checkout/CheckoutService.java @@ -1,8 +1,5 @@ package checkout; -import java.util.ArrayList; -import java.util.List; - public class CheckoutService { private Check check; diff --git a/src/checkout/ConditionByCategory.java b/src/checkout/ConditionByCategory.java index 371ad99..02a07bf 100644 --- a/src/checkout/ConditionByCategory.java +++ b/src/checkout/ConditionByCategory.java @@ -1,22 +1,29 @@ package checkout; +import java.util.function.Predicate; + public class ConditionByCategory implements Condition { Category category; + int totalCost; + Predicate predicate = p -> p.category == category; + + public ConditionByCategory(Category category, int totalCost) { + this.category = category; + this.totalCost = totalCost; + } + public ConditionByCategory(Category category) { this.category = category; + this.totalCost = 0; } @Override public boolean checkCondition(Check check) { - if(check.getCostByCategory(category) != 0){ - return true; - }else{ - return false; - } + return check.getSubCost(predicate) > totalCost; } @Override public int getCostForCondition(Check check) { - return check.getCostByCategory(category); + return check.getSubCost(predicate); } } diff --git a/src/checkout/ConditionByOutlet.java b/src/checkout/ConditionByOutlet.java deleted file mode 100644 index 8fb5ace..0000000 --- a/src/checkout/ConditionByOutlet.java +++ /dev/null @@ -1,22 +0,0 @@ -package checkout; - -public class ConditionByOutlet implements Condition { - Outlet outlet; - public ConditionByOutlet(Outlet outlet) { - this.outlet = outlet; - } - - @Override - public boolean checkCondition(Check check) { - if(check.getCostByOutlet(outlet) != 0){ - return true; - }else{ - return false; - } - } - - @Override - public int getCostForCondition(Check check) { - return check.getCostByOutlet(outlet); - } -} diff --git a/src/checkout/ConditionByTradeMark.java b/src/checkout/ConditionByTradeMark.java new file mode 100644 index 0000000..041cd16 --- /dev/null +++ b/src/checkout/ConditionByTradeMark.java @@ -0,0 +1,27 @@ +package checkout; + +import java.util.function.Predicate; + +public class ConditionByTradeMark implements Condition { + TradeMark tradeMark; + int totalCost; + Predicate productPredicate = p -> p.tradeMark == tradeMark; + public ConditionByTradeMark(TradeMark tradeMark, int totalCost) { + this.tradeMark = tradeMark; + this.totalCost = totalCost; + } + public ConditionByTradeMark(TradeMark tradeMark) { + this.tradeMark = tradeMark; + this.totalCost = 0; + } + + @Override + public boolean checkCondition(Check check) { + return check.getSubCost(productPredicate) > totalCost; + } + + @Override + public int getCostForCondition(Check check) { + return check.getSubCost(productPredicate); + } +} diff --git a/src/checkout/ConditionOfTotalCost.java b/src/checkout/ConditionOfTotalCost.java index b6900f6..eb1b793 100644 --- a/src/checkout/ConditionOfTotalCost.java +++ b/src/checkout/ConditionOfTotalCost.java @@ -7,11 +7,7 @@ public ConditionOfTotalCost(int totalCost) { } public boolean checkCondition(Check check) { - if (check.getTotalCost() < totalCost) { - return false; - }else{ - return true; - } + return totalCost <= check.getTotalCost(); } public int getCostForCondition(Check check) { return check.getTotalPrice(); diff --git a/test/CheckoutServiceTest.java b/test/CheckoutServiceTest.java index 9775d5b..eced323 100644 --- a/test/CheckoutServiceTest.java +++ b/test/CheckoutServiceTest.java @@ -1,7 +1,6 @@ import checkout.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import sun.security.x509.CertAttrSet; import java.time.LocalDate; @@ -20,8 +19,8 @@ void setUp() { checkoutService = new CheckoutService(); checkoutService.openCheck(); - milk_7 = new Product(7, "Milk", Category.MILK, Outlet.PEPSI); - bred_3 = new Product(3, "Bred", Category.BRED, Outlet.ROSHEN); + milk_7 = new Product(7, "Milk", Category.MILK, TradeMark.PEPSI); + bred_3 = new Product(3, "Bred", Category.BRED, TradeMark.ROSHEN); } @Test @@ -47,27 +46,29 @@ void useFactorRewardAndConditionByCategory() { @Test void useFlatRewardAndConditionByCategory() { checkoutService.addProduct(milk_7); - checkoutService.useOffer(new Offer(expiredDate, new FlatReward(100), new ConditionByCategory(Category.MILK))); + checkoutService.useOffer(new Offer(expiredDate, new FlatReward(100), new ConditionByCategory(Category.MILK, 100))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); - assertThat(check.getTotalPoints(), is(117)); + assertThat(check.getTotalPoints(), is(17)); } + @Test void useFlatRewardAndConditionByOutlet() { checkoutService.addProduct(milk_7); - checkoutService.useOffer(new Offer(expiredDate, new FlatReward(30), new ConditionByOutlet(Outlet.ROSHEN))); + checkoutService.useOffer(new Offer(expiredDate, new FlatReward(30), new ConditionByTradeMark(TradeMark.ROSHEN))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); assertThat(check.getTotalPoints(), is(47)); } + @Test void useDiscountRewardAndConditionByOutlet() { checkoutService.addProduct(milk_7); - checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionByOutlet(Outlet.ROSHEN))); + checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionByTradeMark(TradeMark.ROSHEN))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); @@ -78,7 +79,7 @@ void useDiscountRewardAndConditionByOutlet() { @Test void useDiscountRewardAndConditionByOutlet__whenOutletNotFound() { checkoutService.addProduct(milk_7); - checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionByOutlet(Outlet.LAYS))); + checkoutService.useOffer(new Offer(expiredDate, new DiscountReward(50), new ConditionByTradeMark(TradeMark.LAYS, 5))); checkoutService.addProduct(milk_7); checkoutService.addProduct(bred_3); Check check = checkoutService.closeCheck(); From 2de52fb33a31773dab17a674692c1140c5093d37 Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Wed, 6 Mar 2019 09:33:38 +0200 Subject: [PATCH 7/9] remove type from field name --- .idea/uiDesigner.xml | 124 +++++++++++++++++++ src/checkout/Offer.java | 14 +-- src/checkout/Product.java | 6 +- src/checkout/{Outlet.java => TradeMark.java} | 2 +- 4 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 .idea/uiDesigner.xml rename src/checkout/{Outlet.java => TradeMark.java} (68%) diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/checkout/Offer.java b/src/checkout/Offer.java index 33db77e..3ba4737 100644 --- a/src/checkout/Offer.java +++ b/src/checkout/Offer.java @@ -4,19 +4,19 @@ public class Offer { private LocalDate expiredDate; - private Reward rewardType; - private Condition conditionType; + private Reward reward; + private Condition condition; - public Offer(LocalDate expiredDate, Reward rewardType, Condition conditionType) { + public Offer(LocalDate expiredDate, Reward rewardType, Condition condition) { this.expiredDate = expiredDate; - this.rewardType = rewardType; - this.conditionType = conditionType; + this.reward = rewardType; + this.condition = condition; } public void apply(Check check) { - if(expiredDate.isAfter(LocalDate.now()) && conditionType.checkCondition(check)){ - rewardType.applyReward(check, conditionType.getCostForCondition(check)); + if(expiredDate.isAfter(LocalDate.now()) && condition.checkCondition(check)){ + reward.applyReward(check, condition.getCostForCondition(check)); } } } diff --git a/src/checkout/Product.java b/src/checkout/Product.java index 84093c4..1d642a0 100644 --- a/src/checkout/Product.java +++ b/src/checkout/Product.java @@ -4,13 +4,13 @@ public class Product { final int price; final String name; Category category; - Outlet outlet; + TradeMark tradeMark; - public Product(int price, String name, Category category, Outlet outlet) { + public Product(int price, String name, Category category, TradeMark tradeMark) { this.price = price; this.name = name; this.category = category; - this.outlet = outlet; + this.tradeMark = tradeMark; } public Product(int price, String name) { diff --git a/src/checkout/Outlet.java b/src/checkout/TradeMark.java similarity index 68% rename from src/checkout/Outlet.java rename to src/checkout/TradeMark.java index fd427ca..96d70a0 100644 --- a/src/checkout/Outlet.java +++ b/src/checkout/TradeMark.java @@ -1,6 +1,6 @@ package checkout; -public enum Outlet { +public enum TradeMark { PEPSI, ROSHEN, LAYS From 4fe7a03fa249ec81037492ceb56fb0b698012220 Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Wed, 6 Mar 2019 09:47:23 +0200 Subject: [PATCH 8/9] add today date field --- src/checkout/Offer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checkout/Offer.java b/src/checkout/Offer.java index 3ba4737..7f7e726 100644 --- a/src/checkout/Offer.java +++ b/src/checkout/Offer.java @@ -6,7 +6,7 @@ public class Offer { private LocalDate expiredDate; private Reward reward; private Condition condition; - + private LocalDate todayDate = LocalDate.of(2019, 3, 6); public Offer(LocalDate expiredDate, Reward rewardType, Condition condition) { this.expiredDate = expiredDate; @@ -15,7 +15,7 @@ public Offer(LocalDate expiredDate, Reward rewardType, Condition condition) { } public void apply(Check check) { - if(expiredDate.isAfter(LocalDate.now()) && condition.checkCondition(check)){ + if (expiredDate.isAfter(todayDate) && condition.checkCondition(check)) { reward.applyReward(check, condition.getCostForCondition(check)); } } From 8f7c3c3222436b4bb90828be3e6073e76d1c5fda Mon Sep 17 00:00:00 2001 From: oleksiibon Date: Wed, 6 Mar 2019 09:50:55 +0200 Subject: [PATCH 9/9] improve code style --- src/checkout/Check.java | 8 ++++++-- src/checkout/ConditionByTradeMark.java | 2 ++ src/checkout/ConditionOfTotalCost.java | 2 ++ src/checkout/DiscountReward.java | 7 ++++--- src/checkout/FactorReward.java | 5 +++-- src/checkout/FlatReward.java | 5 +++-- src/checkout/Reward.java | 2 +- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/checkout/Check.java b/src/checkout/Check.java index 28ae1fe..ff92263 100644 --- a/src/checkout/Check.java +++ b/src/checkout/Check.java @@ -9,6 +9,7 @@ public class Check { private List offers = new ArrayList<>(); private int points = 0; private double discount = 0; + public int getTotalPrice() { int totalPrice = 0; for (Product product : this.products) { @@ -16,12 +17,14 @@ public int getTotalPrice() { } return totalPrice; } + public double getTotalCost() { double totalCost = 0; totalCost += getTotalPrice(); totalCost -= discount; return totalCost; } + void addProduct(Product product) { products.add(product); } @@ -35,7 +38,7 @@ void addPoints(int points) { } void useOffers(Check check) { - for (Offer offer: offers) { + for (Offer offer : offers) { offer.apply(check); } } @@ -48,8 +51,9 @@ int getSubCost(Predicate predicate) { return products.stream() .filter(predicate) .mapToInt(p -> p.price) - .reduce(0, (a,b) -> a + b); + .reduce(0, (a, b) -> a + b); } + void addDiscount(double discount) { this.discount += discount; } diff --git a/src/checkout/ConditionByTradeMark.java b/src/checkout/ConditionByTradeMark.java index 041cd16..ec691d4 100644 --- a/src/checkout/ConditionByTradeMark.java +++ b/src/checkout/ConditionByTradeMark.java @@ -6,10 +6,12 @@ public class ConditionByTradeMark implements Condition { TradeMark tradeMark; int totalCost; Predicate productPredicate = p -> p.tradeMark == tradeMark; + public ConditionByTradeMark(TradeMark tradeMark, int totalCost) { this.tradeMark = tradeMark; this.totalCost = totalCost; } + public ConditionByTradeMark(TradeMark tradeMark) { this.tradeMark = tradeMark; this.totalCost = 0; diff --git a/src/checkout/ConditionOfTotalCost.java b/src/checkout/ConditionOfTotalCost.java index eb1b793..6ed409d 100644 --- a/src/checkout/ConditionOfTotalCost.java +++ b/src/checkout/ConditionOfTotalCost.java @@ -2,6 +2,7 @@ public class ConditionOfTotalCost implements Condition { int totalCost; + public ConditionOfTotalCost(int totalCost) { this.totalCost = totalCost; } @@ -9,6 +10,7 @@ public ConditionOfTotalCost(int totalCost) { public boolean checkCondition(Check check) { return totalCost <= check.getTotalCost(); } + public int getCostForCondition(Check check) { return check.getTotalPrice(); } diff --git a/src/checkout/DiscountReward.java b/src/checkout/DiscountReward.java index 1bb6103..d8461ac 100644 --- a/src/checkout/DiscountReward.java +++ b/src/checkout/DiscountReward.java @@ -1,12 +1,13 @@ package checkout; -public class DiscountReward implements Reward{ +public class DiscountReward implements Reward { int discount; + public DiscountReward(int discount) { this.discount = discount; } - public void applyReward(Check check, int cost){ - check.addDiscount(cost*discount/100.0); + public void applyReward(Check check, int cost) { + check.addDiscount(cost * discount / 100.0); } } diff --git a/src/checkout/FactorReward.java b/src/checkout/FactorReward.java index d8aa095..c46db7b 100644 --- a/src/checkout/FactorReward.java +++ b/src/checkout/FactorReward.java @@ -2,11 +2,12 @@ public class FactorReward implements Reward { int factor; + public FactorReward(int factor) { this.factor = factor; } - public void applyReward(Check check, int cost){ - check.addPoints(cost*(factor-1)); + public void applyReward(Check check, int cost) { + check.addPoints(cost * (factor - 1)); } } diff --git a/src/checkout/FlatReward.java b/src/checkout/FlatReward.java index 3d99c45..9a80e2c 100644 --- a/src/checkout/FlatReward.java +++ b/src/checkout/FlatReward.java @@ -1,12 +1,13 @@ package checkout; -public class FlatReward implements Reward{ +public class FlatReward implements Reward { int flat; + public FlatReward(int flat) { this.flat = flat; } - public void applyReward(Check check, int cost){ + public void applyReward(Check check, int cost) { check.addPoints(flat); } } diff --git a/src/checkout/Reward.java b/src/checkout/Reward.java index 22b23c5..d1b4c1f 100644 --- a/src/checkout/Reward.java +++ b/src/checkout/Reward.java @@ -1,5 +1,5 @@ package checkout; public interface Reward { - void applyReward(Check check, int cost) ; + void applyReward(Check check, int cost); }