-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCouponChecker.java
More file actions
47 lines (40 loc) · 1.38 KB
/
CouponChecker.java
File metadata and controls
47 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.codedifferently.ReceiptApp;
public class CouponChecker {
//check if a coupon is valid
public boolean couponCheck(String[] acceptedCoupons, String providedCoupon){
boolean isValidCoupon = false;
for (int i=0; i< acceptedCoupons.length; i++){
if(acceptedCoupons[i].equals(providedCoupon.toUpperCase())){
isValidCoupon = true;
//discountVal = discountVal * (i+1);
return isValidCoupon;
}
//don't get a discount
}
return false;
}
//set discount value of coupon
public int discountRate(boolean isCoupon, String[] acceptedCoupons, String providedCoupon){
int discountVal = 25;
if (isCoupon){
for (int i=0; i< acceptedCoupons.length; i++){
if(acceptedCoupons[i].equals(providedCoupon.toUpperCase())){
discountVal = discountVal * (i+1);
return discountVal;
}
//don't get a discount
}
}
return 0;
}
//apply coupon discount to final pricing
public double applyCoupon(boolean isValidCoupon, double subTotal, int discountVal){
if (isValidCoupon){
subTotal = subTotal - (subTotal*discountVal/100);
return subTotal;
}
else{
return subTotal;
}
}
}