-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuction.java
More file actions
77 lines (63 loc) · 1.82 KB
/
Auction.java
File metadata and controls
77 lines (63 loc) · 1.82 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
package AuctioningSystem;
/*
Code: auction auction.java
Class that creates an auction object which holds seller and bidder information as well as the item information.
*/
import java.io.Serializable;
public class Auction implements Serializable {
private User seller;
private Item item;
private User highestBidder;
private Float highestBid;
private int id;
public Auction(Item i){
item = i;
highestBid = new Float(0);
seller = i.getSeller();
}
//Setshighest bid by checking if the bid is higher than the current highest or the starting price
public int setHighestBid(Float bid, User bidder){
if(bid > highestBid && bid > item.getStartingPrice()){
highestBid = bid;
highestBidder = bidder;
return 1;
}
else{
System.out.println("Bid was too low");
return 0;
}
}
public String getSellerName(){
return seller.getName();
}
public int getSellerID(){
return seller.getID();
}
public Float getHighestBid(){
if(highestBid < item.getStartingPrice()){
return item.getStartingPrice();
} else{
return highestBid;
}
}
public User getHighestBidder(){
return highestBidder;
}
public void setId(int number){
id = number;
}
public int getId(){
return id;
}
public Item getItem(){
return item;
}
public void close(int auctionID){
if(highestBid > item.getReservePrice()){
System.out.println("The winner is: " + highestBidder.getName() + " Email: " + highestBidder.getEmail());
}
else{
System.out.println("The reserve price of this bid was not reached, nobody has won this auction.");
}
}
}