Advertisement
lamaulfarid

Auction

Oct 29th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class Auction here.
  4.  *
  5.  * @ Ahmad Lamaul Farid
  6.  * @ 28 Oktober 2020
  7.  */
  8.  
  9. import java.util.ArrayList;
  10. public class Auction
  11. {
  12.    
  13.     private ArrayList<Lot> ListOfItems; // daftar barang yang akan dilelang  
  14.     private int LotsOfIndex; // index barang yang akan dilelang
  15.    
  16.     // inisiasi pelelangan baru
  17.     public Auction()
  18.     {
  19.         ListOfItems = new ArrayList<Lot>();  
  20.         LotsOfIndex = 1;
  21.     }
  22.    
  23.     // untuk memasukkan barang yg akan dilelang
  24.     public void EnterItems(String ItemName)  
  25.     {  
  26.         ListOfItems.add(new Lot(LotsOfIndex, ItemName));  
  27.         LotsOfIndex++;  
  28.     }
  29.    
  30.     // untuk menunjukkan seluruh list barang yang sedang dilelang
  31.     public void ShowListOfItems()  
  32.     {  
  33.         for(Lot lot : ListOfItems) {  
  34.             System.out.println(lot.detail());  
  35.         }    
  36.     }
  37.    
  38.     // untuk mencari lot berdasarkan ID atau index saat ini (current)
  39.     public Lot getLot(int CurrLotsOfIndex)  
  40.     {  
  41.          if((CurrLotsOfIndex > 0) && (CurrLotsOfIndex < LotsOfIndex)) {  
  42.              Lot selectedLot = ListOfItems.get(CurrLotsOfIndex - 1);  
  43.              if(selectedLot.getID() != CurrLotsOfIndex)
  44.              {
  45.                  System.out.println("Internal error : Lot number " +  
  46.                  selectedLot.getID() + " has been returned instead of " +  
  47.                  CurrLotsOfIndex);
  48.                  selectedLot = null;  
  49.              }  
  50.              return selectedLot;  
  51.           }  
  52.           else {  
  53.               System.out.println("Lot number : " + CurrLotsOfIndex +  
  54.               " doesn't exist.");  
  55.               return null;  
  56.             }  
  57.     }
  58.    
  59.     // untuk melakukan bid
  60.     public void MakeABid(int CurrLotsOfIndex, Person bidder, long value)  
  61.     {  
  62.        Lot selectedLot = getLot(CurrLotsOfIndex);  
  63.        if(selectedLot != null) {  
  64.            boolean CheckStatus = selectedLot.bidFor(new Bid(bidder, value));  
  65.            if(CheckStatus) {  
  66.                System.out.println("Bid for Lot number " +  
  67.                CurrLotsOfIndex + " was successful, has been bid by " +
  68.                bidder.getName() + " with price " + "Rp " + value);  
  69.             }  
  70.             else {  
  71.                 Bid highestBid = selectedLot.getHighestBid();  
  72.                 System.out.println("Lot number : " + CurrLotsOfIndex +  
  73.                 "already has a bid of :\t" +  
  74.                 highestBid.getBid());  
  75.             }  
  76.         }  
  77.     }
  78.    
  79.     // untuk menutup pelelangan dan menampilkan siapa yang menang lelang
  80.     public void close()    
  81.     {    
  82.         System.out.println("Auction has been closed.");    
  83.         for(Lot lot : ListOfItems)    
  84.         {    
  85.             System.out.println(lot.getID() + ": " +lot.getLotName());    
  86.             Bid bid = lot.getHighestBid();    
  87.             if (bid==null)    
  88.             {    
  89.                 System.out.println("There is no bid for this Lot");    
  90.             }    
  91.             else    
  92.             {    
  93.                 System.out.println("This Lot has been sold to " +    
  94.                 bid.getBidder().getName() + " with price :\t"    
  95.                 + bid.getBid());    
  96.             }    
  97.         }
  98.     }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement