-
Notifications
You must be signed in to change notification settings - Fork 17
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
InCamp Task #7
base: master
Are you sure you want to change the base?
InCamp Task #7
Changes from 5 commits
619faaf
fe21097
cbce6c6
4d8aebe
6b8cffb
5603fc4
2de52fb
4fe7a03
8f7c3c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package checkout; | ||
|
||
public enum Category { | ||
MILK | ||
MILK, | ||
BRED | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package checkout; | ||
|
||
public interface Condition { | ||
boolean checkCondition(Check check); | ||
|
||
int getCostForCondition(Check check); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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){ | ||
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. configure required amount |
||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int getCostForCondition(Check check) { | ||
return check.getCostByCategory(category); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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){ | ||
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. configure required amount |
||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int getCostForCondition(Check check) { | ||
return check.getCostByOutlet(outlet); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
package checkout; | ||
|
||
public abstract class Offer { | ||
public abstract void apply(Check check); | ||
import java.time.LocalDate; | ||
|
||
public class Offer { | ||
private LocalDate expiredDate; | ||
private Reward rewardType; | ||
private Condition conditionType; | ||
|
||
|
||
public Offer(LocalDate expiredDate, Reward rewardType, Condition conditionType) { | ||
this.expiredDate = expiredDate; | ||
this.rewardType = rewardType; | ||
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. Remove type form field names |
||
this.conditionType = conditionType; | ||
} | ||
|
||
public void apply(Check check) { | ||
if(expiredDate.isAfter(LocalDate.now()) && conditionType.checkCondition(check)){ | ||
rewardType.applyReward(check, conditionType.getCostForCondition(check)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package checkout; | ||
|
||
public enum Outlet { | ||
PEPSI, | ||
ROSHEN, | ||
LAYS | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package checkout; | ||
|
||
public interface Reward { | ||
void applyReward(Check check, int cost) ; | ||
} |
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.
Implement generic
getSubCost
method and passPredicate<Product>
as parameter.