-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
71 lines (57 loc) · 1.27 KB
/
Item.java
File metadata and controls
71 lines (57 loc) · 1.27 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
package edu.cuny.csi.csc330.Restaurant;
public class Item {
private double price;
private String name;
private int bulkQuantity;
private double bulkPrice;
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getBulkQuantity() {
return bulkQuantity;
}
public void setBulkQuantity(int bulkQuantity) {
this.bulkQuantity = bulkQuantity;
}
public double getBulkPrice() {
return bulkPrice;
}
public void setBulkPrice(double bulkPrice) {
this.bulkPrice = bulkPrice;
}
public Item(String n, double p) {
name = n;
price = p;
}
public Item(String n, double p, int bq, double bp) {
name = n;
price = p;
bulkQuantity = bq;
bulkPrice = bp;
}
double priceFor(int quantity) {
double totalPrice = 0.0;
while (quantity > this.bulkQuantity && this.bulkQuantity > 0) {
totalPrice += this.bulkPrice;
quantity /= this.bulkQuantity;
}
totalPrice += (quantity * this.price);
return totalPrice;
}
@Override
public String toString() {
if (bulkQuantity == 0.0) {
return name + ", $" + price;
}
return name + ", $" + price + " (" + bulkQuantity + " for $" + bulkPrice + ")";
}
}