trizehn

Auction

Nov 4th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class Auction here.
  4.  *
  5.  * @author Daffa Tristan Firdaus
  6.  * @version 4 November 2020
  7.  */
  8. import java.util.ArrayList;
  9. public class Auction
  10. {
  11.     private ArrayList<Lot> ListOfItems;
  12.     private int LotsOfIndex;
  13.     public Auction()
  14.     {
  15.         ListOfItems = new ArrayList<Lot>();  
  16.         LotsOfIndex = 1;
  17.     }
  18.     public void EnterItems(String ItemName)  
  19.     {  
  20.         ListOfItems.add(new Lot(LotsOfIndex, ItemName));  
  21.         LotsOfIndex++;  
  22.     }
  23.     public void ShowListOfItems()  
  24.     {
  25.         for(Lot lot : ListOfItems) {  
  26.             System.out.println(lot.detail());  
  27.         }    
  28.     }
  29.     public Lot getLot(int CurrLotsOfIndex)  
  30.     {
  31.         if((CurrLotsOfIndex > 0) && (CurrLotsOfIndex < LotsOfIndex)) {
  32.             Lot selectedLot = ListOfItems.get(CurrLotsOfIndex - 1);
  33.             if(selectedLot.getID() != CurrLotsOfIndex)
  34.             {
  35.                  System.out.println("Internal error : Lot number " +  
  36.                  selectedLot.getID() + " has been returned instead of " +  
  37.                  CurrLotsOfIndex);
  38.                  selectedLot = null;
  39.                 }
  40.                 return selectedLot;
  41.             }
  42.             else {  
  43.               System.out.println("Lot number : " + CurrLotsOfIndex +  
  44.               " doesn't exist.");  
  45.               return null;
  46.             }  
  47.     }
  48.     public void MakeABid(int CurrLotsOfIndex, Person bidder, long value)  
  49.     {
  50.         Lot selectedLot = getLot(CurrLotsOfIndex);
  51.         if(selectedLot != null) {
  52.             boolean CheckStatus = selectedLot.bidFor(new Bid(bidder, value));
  53.             if(CheckStatus) {  
  54.                System.out.println("Bid for Lot number " +  
  55.                     CurrLotsOfIndex + " was successful, has been bid by " +
  56.                     bidder.getName() + " with price " + "Rp " + value);  
  57.             }  
  58.             else {  
  59.                 Bid highestBid = selectedLot.getHighestBid();  
  60.                 System.out.println("Lot number : " + CurrLotsOfIndex +  
  61.                     " already has a bid of :\t" +  highestBid.getBid());  
  62.             }
  63.         }  
  64.     }
  65.     public void close()    
  66.     {    
  67.         System.out.println("Auction has been closed.");    
  68.         for(Lot lot : ListOfItems)    
  69.         {    
  70.             System.out.println(lot.getID() + ": " +lot.getLotName());    
  71.             Bid bid = lot.getHighestBid();    
  72.             if (bid==null)    
  73.             {    
  74.                 System.out.println("There is no bid for this Lot");    
  75.             }    
  76.             else    
  77.             {    
  78.                 System.out.println("This Lot has been sold to " +    
  79.                 bid.getBidder().getName() + " with price :\t"    
  80.                 + bid.getBid());    
  81.             }    
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment