eson332

Untitled

Apr 2nd, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. package InlämningSlutprojekt;
  2.  
  3. /*
  4.  
  5. ---------------------- Class Auction ----------------------------------------------------------------------------------------------------------------
  6.  
  7. */
  8.  
  9. import java.util.ArrayList;
  10. import java.util.Iterator;
  11.  
  12. public class Auction {
  13.  
  14. public Dog auctiondog;
  15. public int auctionnumber;
  16. public ArrayList<Bid> userBids = new ArrayList<Bid>();
  17. public Bid ammount;
  18.  
  19. public Auction(Dog dog, int currentNumber) {
  20. this.auctiondog = dog;
  21. this.auctionnumber = currentNumber;
  22. this.userBids = userBids;
  23. }
  24.  
  25. public void setDogForSale(Dog dog) {
  26. auctiondog = dog;
  27. }
  28.  
  29. public void setNewBid(Bid bid) { userBids.add(bid); }
  30.  
  31. /* public void removeUserFromList(String inputName){
  32.  
  33. for (Bid bid:userBids){
  34. if (bid.getBidUser().name.equals(inputName))
  35. userBids.removeIf(bid -> bid.getBidUser().name.equals(inputName));
  36. }
  37. }*/
  38. public void removeUserFromList(String inputName){
  39. Iterator<Bid> iter = userBids.iterator();
  40. while (iter.hasNext()){
  41. Bid bid = iter.next();
  42. if (bid.getBidUser().name.equals(inputName))
  43. iter.remove();
  44. }
  45. }
  46. public void changeBid(int inputBidaAmmount, String inputName){
  47.  
  48. for (Bid bid:userBids){
  49. if (bid.getBidUser().name.equals(inputName))
  50. bid.setBid(inputBidaAmmount);
  51.  
  52. }
  53. }
  54.  
  55. public ArrayList getBidsList() {
  56. return userBids;
  57. }
  58.  
  59. public int getHighestBid() {
  60.  
  61. int tempvalue = 0;
  62. if (userBids.isEmpty()) {
  63. return 0;
  64. } else {
  65. for (Bid bid : userBids) {
  66.  
  67. if (tempvalue < bid.getAmmount()) {
  68. tempvalue = bid.getAmmount();
  69. }
  70. return tempvalue;
  71. }
  72. }
  73. return 0;
  74. }
  75.  
  76. public boolean checkActiveBid(User inputUser){
  77.  
  78. for (Bid bid : userBids){
  79. if ( inputUser.equals(bid.getBidUser())){
  80. return true;
  81. }
  82. }
  83. return false;
  84. }
  85.  
  86. public String getAuctionDog() {
  87. String dogname = auctiondog.getName();
  88. return dogname;
  89. }
  90.  
  91. public int getNumber() {
  92. return auctionnumber;
  93. }
  94.  
  95. public User getBidUser(String string) {
  96. if (userBids.isEmpty()) {
  97. return null;
  98. }
  99. for (Bid user : userBids) {
  100. if (user.getBidUser().getUserName().equals(string)) {
  101. return user.getBidUser();
  102. } else if (user.getBidUser().findDog(string).getName().equals(string)) {
  103. return user.getBidUser();
  104. } else {
  105. return null;
  106. }
  107. }
  108. return null;
  109. }
  110.  
  111. public User getTopBids() {
  112.  
  113. int tempvalue = 0;
  114. User tempuser = new User("TESTUSER");
  115. if (userBids.isEmpty()) {
  116. return null;
  117. } else {
  118. for (int i=0; i<userBids.size(); i++) {
  119.  
  120. if (tempvalue < userBids.get(i).getAmmount()) {
  121. tempvalue = userBids.get(i).getAmmount();
  122. tempuser = userBids.get(i).getBidUser();
  123.  
  124.  
  125. }
  126. return tempuser;
  127. }
  128. }
  129. return null;
  130. }
  131.  
  132. public String getTopListBids(){
  133.  
  134. ArrayList tempList = userBids;
  135. ArrayList tempListSorted = sortBids(tempList);
  136. tempListSorted.size();
  137. int templistSize = tempListSorted.size();
  138. // System.out.println(templistSize);
  139. if (templistSize < 1){
  140. return "No bids";
  141.  
  142. }else if (templistSize < 2 ){
  143. return sortBids(tempListSorted).get(0) + " ";
  144.  
  145. }else if (templistSize < 3 ){
  146. return sortBids(tempListSorted).get(0) + " " + sortBids(tempListSorted).get(1) + " ";
  147.  
  148. }else if (templistSize < 4 ){
  149. return sortBids(tempListSorted).get(0) + " " + sortBids(tempListSorted).get(1) + " " + sortBids(tempListSorted).get(2);
  150.  
  151. } else if (templistSize > 3 ) {
  152. return sortBids(tempListSorted).get(0) + " " + sortBids(tempListSorted).get(1) + " " + sortBids(tempListSorted).get(2);
  153. }
  154. return "No bids - not if/else";
  155. }
  156.  
  157. public String toString(){
  158. String dogName = getAuctionDog();
  159. int nbr = getNumber();
  160. String topListBids = getTopListBids();
  161.  
  162. /*
  163. ArrayList tempList = userBids;
  164. ArrayList tempListSorted = sortBids(tempList);
  165. */
  166.  
  167.  
  168. return "Auction #"+nbr+": "+ dogName +" Top bids: " + topListBids;
  169.  
  170. }
  171. }
Add Comment
Please, Sign In to add comment