document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.ArrayList;
  2. public class Auction
  3. {
  4.    
  5.     private ArrayList<Lot> lotsArr;  
  6.     private int LotIndex;
  7.     //Inisiasi auction/lelang
  8.     public Auction()
  9.     {
  10.         lotsArr = new ArrayList<Lot>();  
  11.         LotIndex = 1;
  12.     }
  13.     //Memasukkan barang yg akan di lelang
  14.     public void enterLot(String lotName)  
  15.     {  
  16.         lotsArr.add(new Lot(LotIndex, lotName));  
  17.         LotIndex++;  
  18.     }
  19.     //Menunjukkan seluruh list barang yang sedang dilelang
  20.     public void showlotsArr()  
  21.     {  
  22.         for(Lot lot : lotsArr) {  
  23.             System.out.println(lot.detail());  
  24.         }    
  25.     }
  26.     //Mencari lot berdasarkan ID atau index
  27.     public Lot getLot(int CurrentLotIndex)  
  28.     {  
  29.          if((CurrentLotIndex > 0) && (CurrentLotIndex < LotIndex)) {  
  30.              Lot selectedLot = lotsArr.get(CurrentLotIndex - 1);  
  31.              if(selectedLot.getId() != CurrentLotIndex) {
  32.                  
  33.                  System.out.println("Internal error : Lot number " +  
  34.                  selectedLot.getId() +  
  35.                  " has been returned, Not a Lot number " +  
  36.                  CurrentLotIndex);
  37.                  
  38.                  selectedLot = null;  
  39.              }  
  40.              return selectedLot;  
  41.           }  
  42.           else {  
  43.               System.out.println("Lot number : " + CurrentLotIndex +  
  44.               " doesn\'t exist.");  
  45.               return null;  
  46.             }  
  47.     }
  48.     //Melakukan bid
  49.     public void MakeBid(int CurrentLotIndex, Person bidder, long value)  
  50.     {  
  51.        Lot selectedLot = getLot(CurrentLotIndex);  
  52.        if(selectedLot != null) {  
  53.            boolean check = selectedLot.bidFor(new Bid(bidder, value));  
  54.            if(check) {  
  55.                System.out.println("Bid for Lot number " +  
  56.                CurrentLotIndex + " Success, Bidden by " +
  57.                bidder.getName()+ " with price " +value);  
  58.             }  
  59.             else {  
  60.                 Bid highestBid = selectedLot.getHighestBid();  
  61.                 System.out.println("Lot number :\\t" + CurrentLotIndex +  
  62.                 "\\nwith the highest Bid:\\t" +  
  63.                 highestBid.getBid());  
  64.             }  
  65.         }  
  66.     }
  67.     //Menutup pelelangan dan menampilkan siapa yang menang lelang
  68.     public void close()    
  69.     {    
  70.         System.out.println("Auction has ended.");    
  71.         for(Lot lot : lotsArr)    
  72.         {    
  73.             System.out.println(lot.getId() + ": " +lot.getLotName());    
  74.             Bid bid = lot.getHighestBid();    
  75.             if (bid==null)    
  76.             {    
  77.                 System.out.println("There is no bid for this Lot");    
  78.             }    
  79.             else    
  80.             {    
  81.                 System.out.println("This Lot has been sold to " +    
  82.                 bid.getBidder().getName() + " with price :\\t"    
  83.                 + bid.getBid());    
  84.             }    
  85.         }
  86.     }
  87. }
');