Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package InlämningSlutprojekt;
- /*
- ---------------------- Class Auction ----------------------------------------------------------------------------------------------------------------
- */
- import java.util.ArrayList;
- import java.util.Iterator;
- public class Auction {
- public Dog auctiondog;
- public int auctionnumber;
- public ArrayList<Bid> userBids = new ArrayList<Bid>();
- public Bid ammount;
- public Auction(Dog dog, int currentNumber) {
- this.auctiondog = dog;
- this.auctionnumber = currentNumber;
- this.userBids = userBids;
- }
- public void setDogForSale(Dog dog) {
- auctiondog = dog;
- }
- public void setNewBid(Bid bid) { userBids.add(bid); }
- /* public void removeUserFromList(String inputName){
- for (Bid bid:userBids){
- if (bid.getBidUser().name.equals(inputName))
- userBids.removeIf(bid -> bid.getBidUser().name.equals(inputName));
- }
- }*/
- public void removeUserFromList(String inputName){
- Iterator<Bid> iter = userBids.iterator();
- while (iter.hasNext()){
- Bid bid = iter.next();
- if (bid.getBidUser().name.equals(inputName))
- iter.remove();
- }
- }
- public void changeBid(int inputBidaAmmount, String inputName){
- for (Bid bid:userBids){
- if (bid.getBidUser().name.equals(inputName))
- bid.setBid(inputBidaAmmount);
- }
- }
- public ArrayList getBidsList() {
- return userBids;
- }
- public int getHighestBid() {
- int tempvalue = 0;
- if (userBids.isEmpty()) {
- return 0;
- } else {
- for (Bid bid : userBids) {
- if (tempvalue < bid.getAmmount()) {
- tempvalue = bid.getAmmount();
- }
- return tempvalue;
- }
- }
- return 0;
- }
- public boolean checkActiveBid(User inputUser){
- for (Bid bid : userBids){
- if ( inputUser.equals(bid.getBidUser())){
- return true;
- }
- }
- return false;
- }
- public String getAuctionDog() {
- String dogname = auctiondog.getName();
- return dogname;
- }
- public int getNumber() {
- return auctionnumber;
- }
- public User getBidUser(String string) {
- if (userBids.isEmpty()) {
- return null;
- }
- for (Bid user : userBids) {
- if (user.getBidUser().getUserName().equals(string)) {
- return user.getBidUser();
- } else if (user.getBidUser().findDog(string).getName().equals(string)) {
- return user.getBidUser();
- } else {
- return null;
- }
- }
- return null;
- }
- public User getTopBids() {
- int tempvalue = 0;
- User tempuser = new User("TESTUSER");
- if (userBids.isEmpty()) {
- return null;
- } else {
- for (int i=0; i<userBids.size(); i++) {
- if (tempvalue < userBids.get(i).getAmmount()) {
- tempvalue = userBids.get(i).getAmmount();
- tempuser = userBids.get(i).getBidUser();
- }
- return tempuser;
- }
- }
- return null;
- }
- public String getTopListBids(){
- ArrayList tempList = userBids;
- ArrayList tempListSorted = sortBids(tempList);
- tempListSorted.size();
- int templistSize = tempListSorted.size();
- // System.out.println(templistSize);
- if (templistSize < 1){
- return "No bids";
- }else if (templistSize < 2 ){
- return sortBids(tempListSorted).get(0) + " ";
- }else if (templistSize < 3 ){
- return sortBids(tempListSorted).get(0) + " " + sortBids(tempListSorted).get(1) + " ";
- }else if (templistSize < 4 ){
- return sortBids(tempListSorted).get(0) + " " + sortBids(tempListSorted).get(1) + " " + sortBids(tempListSorted).get(2);
- } else if (templistSize > 3 ) {
- return sortBids(tempListSorted).get(0) + " " + sortBids(tempListSorted).get(1) + " " + sortBids(tempListSorted).get(2);
- }
- return "No bids - not if/else";
- }
- public String toString(){
- String dogName = getAuctionDog();
- int nbr = getNumber();
- String topListBids = getTopListBids();
- /*
- ArrayList tempList = userBids;
- ArrayList tempListSorted = sortBids(tempList);
- */
- return "Auction #"+nbr+": "+ dogName +" Top bids: " + topListBids;
- }
- }
Add Comment
Please, Sign In to add comment