document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * @author Timotius Wirawan
  3.  * @version 26 Oktober 2020
  4.  */
  5.  
  6. import java.util.ArrayList;
  7.  
  8. public class Auction
  9. {
  10.    private ArrayList<Lot> daftarlot; //daftar barang lelang
  11.    private int no_Lot; //untuk nomor lelang barang
  12.    
  13.    //lelang baru
  14.    public Auction()
  15.    {  
  16.        daftarlot = new ArrayList<Lot>();  //list barangnya    
  17.        no_Lot = 1;  //nomor lelang barang
  18.    }
  19.    
  20.    //memasukkan barang ke list barang lelang
  21.    public void enterLot(String nama_barang)
  22.    {
  23.        daftarlot.add(new Lot(no_Lot, nama_barang));
  24.        no_Lot++;
  25.     }
  26.    
  27.    //menampilkan semua barang yang dilelang
  28.    public void showLot()
  29.    {
  30.        for(Lot lot : daftarlot)
  31.        {
  32.            System.out.println(lot.toString());
  33.        }
  34.        System.out.println();
  35.    }
  36.    
  37.    public void MakeBid(int CurrentlotNumber, Person bidder, long price)
  38.    {
  39.        Lot selectedLot = getLot(CurrentlotNumber);
  40.        
  41.        if(selectedLot != null)
  42.        {
  43.            boolean successful = selectedLot.bidFor(new Bid(bidder, price));  
  44.            
  45.            //cek dengan penawaran sebelumnya, apakah lebih besar atau tidak
  46.            if(successful)
  47.            {    
  48.                System.out.println("Bid untuk lot nomor " +  
  49.                CurrentlotNumber + " berhasil dilakukan");  
  50.                System.out.println("Bid dilakukan oleh " + bidder.getNamaOrang()+
  51.                                   " dengan harga " +"Rp."+ price);  
  52.             }  
  53.             else
  54.             {
  55.                 //bila penawaran sebelumnya lebih besar, maka penawaran ini gagal  
  56.                 Bid highestBid = selectedLot.getHighestBid();
  57.                 System.out.println("Bid untuk Lot Nomor "+ CurrentlotNumber +
  58.                             " gagal dilakukan");
  59.                 System.out.println("Lot nomor "+ CurrentlotNumber+
  60.                             " memiliki penawaran tertinggi sebesar "+"Rp."+ highestBid.getBid());  
  61.            }
  62.         }
  63.    }
  64.  
  65.    public Lot getLot(int CurrentlotNumber)
  66.    {
  67.        if((CurrentlotNumber >= 1) && (CurrentlotNumber < no_Lot))
  68.        {
  69.            Lot selectedLot = daftarlot.get(CurrentlotNumber - 1);
  70.            if(selectedLot.getid_barang() != CurrentlotNumber)
  71.            {
  72.                System.out.println("Internal error : Lot nomor " +
  73.                     selectedLot.getid_barang() +
  74.                     "telah dikembalikan, bukan lot nomor " +
  75.                     CurrentlotNumber);
  76.                selectedLot = null;
  77.            }
  78.            return selectedLot;
  79.        }
  80.        else
  81.        {
  82.         System.out.println("Lot nomor " + CurrentlotNumber + " tidak tersedia.");  
  83.         return null;
  84.        }
  85.    }
  86.    
  87.    //bid akan berhenti
  88.    public void bidstop()
  89.    {    
  90.        System.out.println("Pelelangan telah berakhir.");    
  91.        for(Lot lot : daftarlot)
  92.        {
  93.            System.out.print(lot.getid_barang() + ". " +lot.getDescription());    
  94.            Bid bid = lot.getHighestBid();
  95.            if (bid==null)
  96.            {
  97.                System.out.print(" : Tidak ada penawaran untuk lot ini");
  98.                System.out.println();
  99.            }
  100.            else
  101.            {
  102.                System.out.println(" : Barang ini terjual kepada " +
  103.                bid.getBidder().getNamaOrang() + " dengan harga : Rp." + bid.getBid());    
  104.            }
  105.         }
  106.    }
  107. }
');