-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRep08DiscountPolicy3.java
More file actions
52 lines (36 loc) · 1.24 KB
/
Rep08DiscountPolicy3.java
File metadata and controls
52 lines (36 loc) · 1.24 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
import java.util.Scanner;
public class Rep08DiscountPolicy3 {
private int variable;
Rep08DiscountPolicy3(int n){
variable = n;
}
public double computeDiscount(int cost, int quantity){
double k = 0.0;
k = quantity / variable;
k = k * cost;
return k;
}
public static void main(String[] args){
int itemCost = 0;
int itemQuantity = 0;
int n = 0;
double discount = 0.0;
double result = 0.0;
double total = 0.0;
Scanner s = new Scanner(System.in);
System.out.printf("Enter the itemCost: ");
itemCost = s.nextInt();
System.out.printf("Enter item quantity: ");
itemQuantity = s.nextInt();
System.out.printf("Enter the number N: ");
n = s.nextInt();
Rep08DiscountPolicy3 p = new Rep08DiscountPolicy3(n);
discount = p.computeDiscount(itemCost, itemQuantity);
total = itemCost * itemQuantity;
result = total - discount;
System.out.println("[Result]");
System.out.printf("Total before discount: %.1f\n",total);
System.out.printf("Discount amount: %.1f\n",discount);
System.out.printf("Final price: %.1f\n",result);
}
}