-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRep08DiscountPolicy2.java
More file actions
60 lines (43 loc) · 1.44 KB
/
Rep08DiscountPolicy2.java
File metadata and controls
60 lines (43 loc) · 1.44 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
import java.util.Scanner;
public class Rep08DiscountPolicy2 {
private int minimum;
private double percent;
Rep08DiscountPolicy2(int a, double b){
minimum = a;
percent = b;
}
public double computeDiscount(int count, int itemCost){
if(count > minimum)
return 1;
else
return 0;
}
public static void main(String[] args){
int minimum = 0;
int itemCost = 0;
int percent = 0;
int itemQuantity = 0;
double discount = 0.0;
double result = 0.0;
Scanner s = new Scanner(System.in);
System.out.printf("Enter the minimum: ");
minimum = s.nextInt();
System.out.printf("Enter the itemCost: ");
itemCost = s.nextInt();
System.out.printf("Enter the discount percent: ");
percent = s.nextInt();
System.out.printf("Enter item quantity: ");
itemQuantity = s.nextInt();
Rep08DiscountPolicy2 p = new Rep08DiscountPolicy2(minimum, percent);
discount = p.computeDiscount(itemQuantity,itemCost);
if(discount == 1){
result = (itemCost * itemQuantity);
result = result - ((itemCost * itemQuantity) * percent/100.0);
System.out.printf("Res: %.1f",result);
}
else{
result = (itemCost * itemQuantity);
System.out.printf("Res: %.1f",result);
}
}
}