AUCTION.JAVA
package English_Auction;
/**
*
*
*/
public class Auction
{
// A unique identifying number.
private final int number;
// A description of the lot.
private String description;
//
private int startPrice;
//
private int reserve;
// The current highest bid for this lot.
private Bid highbid;
//
private Bid highestBid;
/**
* Construct a Lot, setting its number and description.
* @param number The lot number.
* @param description A description of this lot.
* @param startPrice
* @param reserve
*/
public Auction(int number, String description, int startPrice, int reserve)
{
this.number = number;
this.description = description;
this.startPrice = startPrice;
this.reserve = reserve;
}
/**
* Attempt to bid for this lot. A successful bid
* must have a value higher than any existing bid.
* @param bid A new bid.
* @return true if successful, false otherwise
*/
public boolean bidFor(Bid bid)
{
if((highbid == null) ||
(bid.getValue() > highbid.getValue())) {
// This bid is the best so far.
highbid = bid;
return true;
}
else {
return false;
}
}
/**
* @return A string representation of this lot's details.
*/
public String toString()
{
String details = number + ": " + description + " Start " + startPrice + " Reserve "+ reserve;
if(highbid != null) {
details += " Bid: " +
highbid.getValue();
}
else {
details += " (No bid)";
}
return details;
}
/**
* @return The lot's number.
*/
public int getNumber()
{
return number;
}
/**
* @return The lot's description.
*/
public String getDescription()
{
return description;
}
/**
* @return The highest bid for this lot.
* This could be null if there is
* no current bid.
*/
public Bid gethighbid()
{
return highbid;
}
public int findHighestBidder(Bid bid)
{
if((highestBid == null) ||
(bid.getValue() > highestBid.getValue())) {
// This bid is the best so far.
highestBid = bid;
return (int)(highestBid.getValue());
}
else {
//return 0;
return (int)(highestBid.getValue());
}
}
}
BID.JAVA
package English_Auction;
/**
*
*
*/
//public class Bid {
public class Bid
{
// The person making the bid.
private final Bidder bidder;
// The value of the bid. This could be a large number so
// the long type has been used.
private final long value;
/**
* Create a bid.
* @param bidder Who is bidding for the lot.
* @param value The value of the bid.
*/
public Bid(Bidder bidder, long value)
{
this.bidder = bidder;
this.value = value;
}
/**
* @return The bidder.
*/
public Bidder getBidder()
{
return bidder;
}
/**
* @return The value of the bid.
*/
public long getValue()
{
return value;
}
}
BIDDER.JAVA
package English_Auction;
/**
*
*
*/
//public class Bidder {
public class Bidder
{
// The name of this person.
private final String name;
private int strategy;
/**
* Create a new person with the given name.
* @param name The person's name.
*/
public Bidder(String name, int strategy)
{
this.name = name;
this.strategy = strategy;
}
/**
* @return The person's name.
*/
public String getName()
{
return name;
}
}
//}
HIGHESTBIDDER.java
package English_Auction;
/**
*
*
*/
public class HigherBidder {
//public class HighestBidder {
Bid highestBid;
public int findHighestBidder(Bid bid)
{
if((highestBid == null) ||
(bid.getValue() > highestBid.getValue())) {
// This bid is the best so far.
highestBid = bid;
return (int)(highestBid.getValue());
}
else {
return 0;
}
}
}
//}
runauction.java
package English_Auction;
/**
*
*
*/
public class RunAuction {
//public class RunAution {
public static void main(String[] args) {
Bidder B1= new Bidder("John",1);
Bidder B2= new Bidder("Paul",1);
Bidder B3= new Bidder("Peter",1);
Auction ac = new Auction(1,"Ferrari", 10000, 30000);
//HighestBidder HB1= new HighestBidder();
Bid b1=new Bid(B2,5000);
Bid b2=new Bid(B1,10000);
Bid b3=new Bid(B3,15000);
System.out.println(ac.findHighestBidder(b1));
System.out.println(ac.findHighestBidder(b3));
System.out.println(ac.findHighestBidder(b1));
}
}
//}
I am trying to get the highest bid from the bids that have been passed.
when someone bids, I would like to get the bid value into an array of n size and then do bubble sort to get the highest bid value. I could not get this work..could anyone please give me some hints. Any help much appreciated.
Many thanks
Dee