Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/vcs.xml
.idea/workspace.xml
.idea/misc.xml
out
3 changes: 2 additions & 1 deletion src/checkout/AnyGoodsOffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public AnyGoodsOffer(int totalCost, int points) {

@Override
public void apply(Check check) {

if (this.totalCost <= check.getTotalCost())
check.addPoints(this.points);
}
}
11 changes: 0 additions & 11 deletions src/checkout/CheckoutService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
3 changes: 2 additions & 1 deletion src/checkout/FactorByCategoryOffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public FactorByCategoryOffer(Category category, int factor) {

@Override
public void apply(Check check) {

int points = check.getCostByCategory(this.category);
check.addPoints(points * (this.factor - 1));
}
}