Advertisement
mnaufaldillah

Lot Tugas 3

Oct 24th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1.  
  2. /**
  3.  * A class to medel an item (or set of items) in an
  4.  * auction: a lot
  5.  *
  6.  * @author Muhammad Naufaldillah
  7.  * @version 22 October 2020
  8.  */
  9. public class Lot
  10. {
  11.     // A unique identifying number.
  12.     private final int number;
  13.     // A description of the lot.
  14.     private String description;
  15.     // The current highest bid for this lot.
  16.     private Bid highestBid;
  17.    
  18.     /**
  19.      * Construct a Lot, setting its number and description.
  20.      * @param number The lot number.
  21.      * @param description. A description of this lot.
  22.      */
  23.     public Lot(int number, String description)
  24.     {
  25.         this.number = number;
  26.         this.description = description;
  27.     }
  28.    
  29.     /**
  30.      * Attempt to bid for this lot. A successful bid
  31.      *  must have a value higher than any existing bid.
  32.      *  @param bid A new bid.
  33.      *  @return true if successful, false otherwise
  34.      */
  35.     public boolean bidFor(Bid bid)
  36.     {
  37.         if(highestBid == null)
  38.         {
  39.             // There is no previous bid.
  40.             highestBid = bid;
  41.             return true;
  42.         }
  43.         else if (bid.getValue() > highestBid.getValue())
  44.         {
  45.             //The bid is better than the previous one.
  46.             highestBid = bid;
  47.             return true;
  48.         }
  49.         else
  50.         {
  51.             //The bid is not better
  52.             return false;
  53.         }
  54.     }
  55.    
  56.     /**
  57.      * @return A string representation of this lot's details.
  58.      */
  59.     public String toString()
  60.     {
  61.         String details = number + ": " + description;
  62.         if(highestBid != null)
  63.         {
  64.             details += "    Bid:  " + highestBid.getValue();
  65.         }
  66.         else
  67.         {
  68.             details += "    (No bid)";
  69.         }
  70.         return details;
  71.     }
  72.    
  73.     /**
  74.      * @return The lot's number
  75.      */
  76.     public int getNumber()
  77.     {
  78.         return number;
  79.     }
  80.    
  81.     /**
  82.      * @return The lot's description
  83.      */
  84.     public String getDescription()
  85.     {
  86.         return description;
  87.     }
  88.    
  89.     /**
  90.      * @return The highest bid for this lot.
  91.      * This could be null if there is no current bid
  92.      */
  93.     public Bid getHighestBid()
  94.     {
  95.         return highestBid;
  96.     }
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement