document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * A class to model an item an item (or set of items) in an auction: a lot.  
  3.  *
  4.  * @author (Fika Nur Aini)
  5.  * @version (22 October 2020)
  6.  */
  7. public class Lot
  8. {
  9.    // A unique identifying number.  
  10.    private final int number;  
  11.    //A description of the lot.  
  12.    private String description;  
  13.    // The current highest bid for this lot.  
  14.    private Bid highestBid;  
  15.    /**  
  16.     * Construct a Lot, setting its number and description.  
  17.     * @param number The lot number.  
  18.     * @param description A description of this lot.  
  19.     */  
  20.    public Lot(int number, String description)  
  21.    {  
  22.      this.number = number;  
  23.      this.description = description;  
  24.    }  
  25.    /**  
  26.     * Attempt to bid for this lot. A successful bid  
  27.     * must have a value higher than any existing bid.  
  28.     * @param bid A new bid.  
  29.     * @return true if successful, false otherwise.  
  30.     */  
  31.    public boolean bidFor(Bid bid)  
  32.    {  
  33.      if((highestBid == null)||(bid.getValue() > highestBid.getValue()))  
  34.      {  
  35.        // This bid is the best so far  
  36.        highestBid = bid;  
  37.        return true;  
  38.      }  
  39.      else{  
  40.        return false;  
  41.      }  
  42.    }  
  43.    /**  
  44.     * @return A string representation of this lot\'s details.  
  45.     */  
  46.    public String toString()  
  47.    {  
  48.      String details = number + ": " + description;  
  49.      if(highestBid!=null) {  
  50.        details+= "  Bid: " +highestBid.getValue();  
  51.      }  
  52.      else {  
  53.        details += "  (No bid)";  
  54.      }  
  55.      return details;  
  56.    }  
  57.    /**  
  58.     * @return The lot\'s number.  
  59.     */  
  60.    public int getNumber()  
  61.    {  
  62.      return number;  
  63.    }  
  64.    /**  
  65.     * @return The lot\'s description.  
  66.     */  
  67.    public String getDescription()  
  68.    {  
  69.      return description;  
  70.    }  
  71.    /**  
  72.     * @return The highest bid for this lot.  
  73.     * This could be null if there is no current bid.  
  74.     */  
  75.    public Bid getHighestBid()  
  76.    {  
  77.      return highestBid;  
  78.    }  
  79.  
  80. }
  81.  
');