Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Auction here.
- *
- * @ Ahmad Lamaul Farid
- * @ 28 Oktober 2020
- */
- import java.util.ArrayList;
- public class Auction
- {
- private ArrayList<Lot> ListOfItems; // daftar barang yang akan dilelang
- private int LotsOfIndex; // index barang yang akan dilelang
- // inisiasi pelelangan baru
- public Auction()
- {
- ListOfItems = new ArrayList<Lot>();
- LotsOfIndex = 1;
- }
- // untuk memasukkan barang yg akan dilelang
- public void EnterItems(String ItemName)
- {
- ListOfItems.add(new Lot(LotsOfIndex, ItemName));
- LotsOfIndex++;
- }
- // untuk menunjukkan seluruh list barang yang sedang dilelang
- public void ShowListOfItems()
- {
- for(Lot lot : ListOfItems) {
- System.out.println(lot.detail());
- }
- }
- // untuk mencari lot berdasarkan ID atau index saat ini (current)
- public Lot getLot(int CurrLotsOfIndex)
- {
- if((CurrLotsOfIndex > 0) && (CurrLotsOfIndex < LotsOfIndex)) {
- Lot selectedLot = ListOfItems.get(CurrLotsOfIndex - 1);
- if(selectedLot.getID() != CurrLotsOfIndex)
- {
- System.out.println("Internal error : Lot number " +
- selectedLot.getID() + " has been returned instead of " +
- CurrLotsOfIndex);
- selectedLot = null;
- }
- return selectedLot;
- }
- else {
- System.out.println("Lot number : " + CurrLotsOfIndex +
- " doesn't exist.");
- return null;
- }
- }
- // untuk melakukan bid
- public void MakeABid(int CurrLotsOfIndex, Person bidder, long value)
- {
- Lot selectedLot = getLot(CurrLotsOfIndex);
- if(selectedLot != null) {
- boolean CheckStatus = selectedLot.bidFor(new Bid(bidder, value));
- if(CheckStatus) {
- System.out.println("Bid for Lot number " +
- CurrLotsOfIndex + " was successful, has been bid by " +
- bidder.getName() + " with price " + "Rp " + value);
- }
- else {
- Bid highestBid = selectedLot.getHighestBid();
- System.out.println("Lot number : " + CurrLotsOfIndex +
- "already has a bid of :\t" +
- highestBid.getBid());
- }
- }
- }
- // untuk menutup pelelangan dan menampilkan siapa yang menang lelang
- public void close()
- {
- System.out.println("Auction has been closed.");
- for(Lot lot : ListOfItems)
- {
- System.out.println(lot.getID() + ": " +lot.getLotName());
- Bid bid = lot.getHighestBid();
- if (bid==null)
- {
- System.out.println("There is no bid for this Lot");
- }
- else
- {
- System.out.println("This Lot has been sold to " +
- bid.getBidder().getName() + " with price :\t"
- + bid.getBid());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement