-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.java
More file actions
28 lines (24 loc) · 809 Bytes
/
Copy pathDemo.java
File metadata and controls
28 lines (24 loc) · 809 Bytes
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
public class Demo {
public static void main(String argv[]) {
Order order = new Order("Shane", 444.0f);
DiscountStrategy strategy = null;
int selectedStrat = Integer.parseInt(argv[0]);
float amt = Float.parseFloat(argv[1]);
switch(selectedStrat) {
case 1:
strategy = new PercentDiscountStrategy(amt);
break;
case 2:
strategy = new StoreCreditDiscountStrategy(amt);
break;
case 3:
strategy = new RandomDiscountStrategy();
break;
default:
throw new RuntimeException("Unknown type: " + selectedStrat);
}
System.out.println("Hello " + order.getName());
System.out.println("The full price of your order was " + order.getPrice());
System.out.println("Your discount price is " + strategy.applyDiscount(order));
}
}