Java Reference
In-Depth Information
LISTING 6.2
Continued
7: private String name;
8: private double retail;
9: private int quantity;
10: private double price;
11:
12: Item(String idIn, String nameIn, String retailIn, String quanIn) {
13: id = idIn;
14: name = nameIn;
15: retail = Double.parseDouble(retailIn);
16: quantity = Integer.parseInt(quanIn);
17:
18: if (quantity > 400)
19: price = retail * .5D;
20: else if (quantity > 200)
21: price = retail * .6D;
22: else
23: price = retail * .7D;
24: price = Math.floor( price * 100 + .5 ) / 100;
25: }
26:
27: public int compareTo(Object obj) {
28: Item temp = (Item)obj;
29: if (this.price < temp.price)
30: return 1;
31: else if (this.price > temp.price)
32: return -1;
33: return 0;
34: }
35:
36: public String getId() {
37: return id;
38: }
39:
40: public String getName() {
41: return name;
42: }
43:
44: public double getRetail() {
45: return retail;
46: }
47:
48: public int getQuantity() {
49: return quantity;
50: }
51:
52: public double getPrice() {
53: return price;
54: }
55: }
 
Search WWH ::




Custom Search