-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuctionItem.java
More file actions
89 lines (79 loc) · 2.44 KB
/
Copy pathAuctionItem.java
File metadata and controls
89 lines (79 loc) · 2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.Serializable;
import java.util.HashMap;
public class AuctionItem implements Serializable {
private static final long serialVersionUID = 6232100136411267879L;
private int itemId;
private String itemTitle;
private float price;
private float reserve;
private String itemDescription;
private String itemCondition;
private ClientId seller;
private ClientId highestBidder;
private boolean active;
private HashMap<Integer, Float> bidders;
public AuctionItem(int itemId, String itemTitle, float price, float reserve, String itemDescription, String itemCondition, ClientId seller) {
this.itemId = itemId;
this.itemTitle = itemTitle;
this.itemDescription = itemDescription;
this.itemCondition = itemCondition;
this.price = price;
this.reserve = reserve;
this.seller = seller;
this.active = true;
if(itemDescription.equals(""))
itemDescription = "No Description.";
bidders = new HashMap<Integer, Float>();
}
public void bid(float bid, ClientId bidder) {
if(bid > price && bidder != seller) {
price = bid;
highestBidder = bidder;
bidders.put(bidder.getId(), bid);
}
}
public int getId() {
return itemId;
}
public String getTitle() {
return itemTitle;
}
public String getDescription() {
return itemDescription;
}
public String getCondition() {
return itemCondition;
}
public float getPrice() {
return price;
}
public float getReserve() {
return reserve;
}
public ClientId getSeller() {
return seller;
}
public ClientId getBidder() {
return highestBidder;
}
public boolean isActive() {
return active;
}
public void close() {
active = false;
}
public ClientId getHighestBidder() {
return highestBidder;
}
public HashMap<Integer, Float> getBidders() {
return bidders;
}
public String toString() {
return "ID: " + Integer.toString(itemId) +
"\nItem Name: " + itemTitle +
"\nPrice: \u00A3" + String.format("%.2f", price) +
"\nDescription: " + itemDescription +
"\nCondition: " + itemCondition +
"\n";
}
}