-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
33 lines (30 loc) · 840 Bytes
/
Copy pathSolution.java
File metadata and controls
33 lines (30 loc) · 840 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
29
30
31
32
33
class Cashier
{
private final int[] pricesByProductId;
private final int n;
private final double discount;
private int counter = 0;
public Cashier(int n, int discount, int[] products, int[] prices)
{
this.n = n;
this.discount = 1 - ((double) discount / 100);
pricesByProductId = new int[201];
for (int i = 0; i < products.length; i++)
{
pricesByProductId[products[i]] = prices[i];
}
}
public double getBill(int[] product, int[] amount)
{
double billAmount = 0;
for (int i = 0; i < product.length; i++)
{
billAmount += pricesByProductId[product[i]] * amount[i];
}
if (++counter % n == 0)
{
billAmount = billAmount * discount;
}
return billAmount;
}
}