document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.ArrayList;
  2.  
  3. /**
  4.  * Auction.java
  5.  * Ghifari Astaudi Ukumullah
  6.  * @version 26 October 2020
  7.  */
  8. public class Auction
  9. {
  10.     // The list of Lots in this auction.
  11.     private ArrayList<Lot> lots;
  12.     // The number that will be given to the next lot entered
  13.     // into this auction
  14.     private int nextLotNumber;
  15.    
  16.     /**
  17.      * Creat a new auction.
  18.      */
  19.     public Auction()
  20.     {
  21.         lots = new ArrayList<Lot>();
  22.         nextLotNumber = 1;
  23.     }
  24.    
  25.     /**
  26.      * Enter a new lot into the auction.
  27.      * @param description A description of the lot.
  28.      *
  29.      */
  30.     public void enterLot(String description)
  31.     {
  32.         lots.add(new Lot(nextLotNumber, description));
  33.         nextLotNumber++;
  34.     }
  35.    
  36.     /**
  37.      * Show the full list of lots in this auction
  38.      */
  39.     public void showLots()
  40.     {
  41.         for(Lot lot : lots)
  42.         {
  43.             System.out.println(lot.toString());
  44.         }
  45.     }
  46.    
  47.     /**
  48.      * Make a bid for a lot.
  49.      * A message is printed indicating whether the bid os
  50.      * successful or not
  51.      * @param lotNumber The lot being bid for.
  52.      * @param bidder The person bidding for the lot.
  53.      * @param value The value of the bid.
  54.      */
  55.     public void makeAbid(int lotNumber, Person bidder, long value)
  56.     {
  57.         Lot selectedLot = getLot(lotNumber);
  58.         if(selectedLot != null)
  59.         {
  60.             Bid bid = new Bid(bidder, value);
  61.             boolean successful = selectedLot.bidFor(bid);
  62.             if(successful)
  63.             {
  64.                 System.out.println("The bid for lot number" +
  65.                                     lotNumber + " was suecessful.");
  66.             }
  67.             else
  68.             {
  69.                 // Report which bid is higher
  70.                 Bid highestBid = selectedLot.getHighestBid();
  71.                 System.out.println("Lot number: " + lotNumber +
  72.                                    " already has a bid of: " + highestBid.getValue());
  73.             }
  74.         }
  75.     }
  76.    
  77.     /**
  78.      * Return the lot with given number. Return null
  79.      * if a lot with this number does not exist.
  80.      * @param lotNUmber The number of the lot to return
  81.      */
  82.     public Lot getLot(int lotNumber)
  83.     {
  84.         if((lotNumber >= 1) && (lotNumber < nextLotNumber))
  85.         {
  86.             // The number seems to be reasonable.
  87.             Lot selectedLot = lots.get(lotNumber - 1);
  88.             // Include aconfidence check to be sure we have the
  89.             // right lot.
  90.             if (selectedLot.getNumber() != lotNumber)
  91.             {
  92.                 System.out.println("Internal error: Lot number " +
  93.                                    selectedLot.getNumber() +
  94.                                    " was returned instead of " + lotNumber);
  95.                 // Don\'t return an invalid lot.
  96.                 selectedLot = null;
  97.             }
  98.             return selectedLot;
  99.         }
  100.         else
  101.         {
  102.             System.out.println("Lot number: " + lotNumber +
  103.                                " does not exist.");
  104.             return null;
  105.         }
  106.     }
  107. }
');