-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCouponCodes.java
More file actions
78 lines (71 loc) · 2.71 KB
/
Copy pathCouponCodes.java
File metadata and controls
78 lines (71 loc) · 2.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class CouponCodes {
static Map<String, CouponCodes> couponList = new HashMap<>();
static Scanner input = new Scanner(System.in);
String Code;
int DiscountAmount;
boolean isValidCode;
public CouponCodes(String code, int discount) {
this.Code = code;
this.DiscountAmount = discount;
this.isValidCode = true;
}
public static void CouponCodesControlPanel() {
System.out.println("1 -> Create CouponCode\n2 -> Update CouponCode\n3 -> Delete CouponCode\n4 -> List of All Coupons\n5 -> Back\nChoice :");
int choice = input.nextInt();
switch (choice){
case 1:
CreateCouponCode();
break;
case 2:
UpdateCoupon();
break;
case 3:
System.out.println("Enter Code");
String code = input.nextLine();
if(!isExistingCoupon(code)) return;
couponList.remove(code);
System.out.println("Coupon Deleted");
break;
case 4:
printAllCouponCodes();
break;
case 5:
AdminControlPanel.AdminControls("admin", "password");
break;
}
CouponCodesControlPanel();
}
private static void printAllCouponCodes() {
System.out.println("Code Discount Amount Availability");
for (CouponCodes code:couponList.values()){
System.out.println(code.Code+" "+code.DiscountAmount+" "+code.isValidCode);
}
System.out.println("========== End Of List ==========");
}
private static void UpdateCoupon() {
System.out.println("Enter Code");
String code = input.nextLine();
if(!isExistingCoupon(code)) return;
CouponCodes currentCoupon = couponList.get(code);
System.out.println("Enter Discount");
currentCoupon.DiscountAmount = input.nextInt();
currentCoupon.isValidCode = true;
System.out.println("Coupon Discount Updated!");
}
private static boolean isExistingCoupon(String code) {
boolean isExistingCode = couponList.containsKey(code);
if(!isExistingCode) System.out.println("Invalid Coupon!");
return isExistingCode;
}
private static void CreateCouponCode() {
System.out.println("Enter Code, Discount value");
String code = input.next();
int discount = input.nextInt();
CouponCodes newCoupon = new CouponCodes(code,discount);
couponList.put(code, newCoupon);
System.out.println("====> Coupon code created!");
}
}