document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. @author Albert Filip Silalahi
  3. @version 4 Nov 2020
  4. */
  5.  
  6. import java.util.ArrayList;
  7. public class Auction
  8. {
  9.  
  10. private ArrayList<Lot> ListOfItems; // daftar barang yang akan dilelang
  11. private int LotsOfIndex; // index barang yang akan dilelang
  12.  
  13. // inisiasi pelelangan baru
  14. public Auction()
  15. {
  16. ListOfItems = new ArrayList<Lot>();
  17. LotsOfIndex = 1;
  18. }
  19.  
  20. // untuk memasukkan barang yg akan dilelang
  21. public void EnterItems(String ItemName)
  22. {
  23. ListOfItems.add(new Lot(LotsOfIndex, ItemName));
  24. LotsOfIndex++;
  25. }
  26.  
  27. // untuk menunjukkan seluruh list barang yang sedang dilelang
  28. public void ShowListOfItems()
  29. {
  30. for(Lot lot : ListOfItems) {
  31. System.out.println(lot.detail());
  32. }
  33. }
  34.  
  35. // untuk mencari lot berdasarkan ID atau index saat ini (current)
  36. public Lot getLot(int CurrLotsOfIndex)
  37. {
  38. if((CurrLotsOfIndex > 0) && (CurrLotsOfIndex < LotsOfIndex)) {
  39. Lot selectedLot = ListOfItems.get(CurrLotsOfIndex - 1);
  40. if(selectedLot.getID() != CurrLotsOfIndex)
  41. {
  42. System.out.println("Internal error : Lot number " +
  43. selectedLot.getID() + " has been returned instead of " +
  44. CurrLotsOfIndex);
  45. selectedLot = null;
  46. }
  47. return selectedLot;
  48. }
  49. else {
  50. System.out.println("Lot number : " + CurrLotsOfIndex +
  51. " doesn't exist.");
  52. return null;
  53. }
  54. }
  55.  
  56. // melakukan tawaran
  57. public void MakeABid(int CurrLotsOfIndex, Person bidder, long value)
  58. {
  59. Lot selectedLot = getLot(CurrLotsOfIndex);
  60. if(selectedLot != null) {
  61. boolean CheckStatus = selectedLot.bidFor(new Bid(bidder, value));
  62. if(CheckStatus) {
  63. System.out.println("Bid for Lot number " +
  64. CurrLotsOfIndex + " was successful, has been bid by " +
  65. bidder.getName() + " with price " + "Rp " + value);
  66. }
  67. else {
  68. Bid highestBid = selectedLot.getHighestBid();
  69. System.out.println("Lot number : " + CurrLotsOfIndex +
  70. "already has a bid of :\\t" +
  71. highestBid.getBid());
  72. }
  73. }
  74. }
  75.  
  76. // menutup pelelangan dan menampilkan pemenang lelang
  77. public void close()
  78. {
  79. System.out.println("Auction has been closed.");
  80. for(Lot lot : ListOfItems)
  81. {
  82. System.out.println(lot.getID() + ": " +lot.getLotName());
  83. Bid bid = lot.getHighestBid();
  84. if (bid==null)
  85. {
  86. System.out.println("There is no bid for this Lot");
  87. }
  88. else
  89. {
  90. System.out.println("This Lot has been sold to " +
  91. bid.getBidder().getName() + " with price :\\t"
  92. + bid.getBid());
  93. }
  94. }
  95. }
  96. }
');