-
Notifications
You must be signed in to change notification settings - Fork 17
Homework ;) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Homework ;) #5
Changes from all commits
2361738
bdf70cb
ae43933
e4c7f52
f57020a
87ffdde
38496e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package checkout; | ||
|
|
||
| public class ByCategory implements Condition { | ||
| private Category category; | ||
|
|
||
| public ByCategory(Category category) { | ||
| this.category = category; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean inCondition(Check check) { | ||
| return check.getCostByCategory(category) > 0; | ||
| } | ||
|
|
||
| @Override | ||
| public int getPointsByCondition(Check check) { | ||
| return check.getCostByCategory(category); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package checkout; | ||
|
|
||
| public class ByTrademark implements Condition { | ||
| private Trademark trademark; | ||
|
|
||
| public ByTrademark(Trademark trademark) { | ||
| this.trademark = trademark; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean inCondition(Check check) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chose better method name |
||
| return check.getCostByTrademark(trademark) > 0; | ||
| } | ||
|
|
||
| @Override | ||
| public int getPointsByCondition(Check check) { | ||
| return check.getCostByTrademark(trademark); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package checkout; | ||
|
|
||
| public enum Category { | ||
| MILK | ||
| MILK, | ||
| MEAT | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package checkout; | ||
|
|
||
| public interface Condition { | ||
| boolean inCondition(Check check); | ||
|
|
||
| int getPointsByCondition(Check check); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package checkout; | ||
|
|
||
| public class Discount implements Reward { | ||
| private int discont; | ||
|
|
||
| public Discount(int discont) { | ||
| this.discont = discont; | ||
| } | ||
|
|
||
| @Override | ||
| public void useReward(Check check, Condition condition) { | ||
| int points = condition.getPointsByCondition(check); | ||
| check.addDiscount((int) Math.round(points * (discont / 100d))); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package checkout; | ||
|
|
||
| public class Factor implements Reward { | ||
| private int factor; | ||
|
|
||
| public Factor(int factor) { | ||
| this.factor = factor; | ||
| } | ||
|
|
||
| @Override | ||
| public void useReward(Check check, Condition condition) { | ||
| int points = condition.getPointsByCondition(check); | ||
| check.addPoints(points * (factor - 1)); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package checkout; | ||
|
|
||
| public class Flat implements Reward { | ||
| private int points; | ||
|
|
||
| public Flat(int points) { | ||
| this.points = points; | ||
| } | ||
|
|
||
| @Override | ||
| public void useReward(Check check, Condition condition) { | ||
| check.addPoints(points); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| package checkout; | ||
|
|
||
| import java.util.Date; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
|
||
| public abstract class Offer { | ||
| public abstract void apply(Check check); | ||
| public boolean isValid(Date expirationDate) { | ||
| return expirationDate.after(new Date()); | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,23 @@ public class Product { | |
| final int price; | ||
| final String name; | ||
| Category category; | ||
| Trademark trademark; | ||
|
|
||
| public Product(int price, String name, Category category) { | ||
| this.price = price; | ||
| this.name = name; | ||
| this.category = category; | ||
| } | ||
|
|
||
| public Product(int price, String name, Category category, Trademark trademark) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constructor duplication |
||
| this.price = price; | ||
| this.name = name; | ||
| this.category = category; | ||
| this.trademark = trademark; | ||
| } | ||
|
|
||
|
|
||
| public Product(int price, String name) { | ||
| this(price, name, null); | ||
| this(price, name, null, null); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract amount into field