I'm setting up an eAuction system and I want to make a list for each buyer of the auctions which they have won. However, I cannot seem to pass a string from one class to a linked list in another. I've had a look through the site about passing string from one class to another but none of them have worked.
I've tried passing it simply using the .add method but it keeps giving me suggestions that don't work.
This is my Auction class
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedList;
import java.util.List;
public class Auction {
private int auctionID;
private boolean blocked = false;
private double startPrice, reservePrice;
private LocalDateTime closeDate;
private Item item;
private double UP, LOW;
private double currentBid;
private List<Bid> bids = new LinkedList<>();
private Status status;
private User seller;
private boolean itemFound;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MM yyyy");
private double bidAmount;
private User highestBidder;
public Auction(double startPrice, double reservePrice, double currentBid, User highestBidder,
LocalDateTime closeDate, Item item, User seller, Status status) throws Exception {
if (closeDate.isBefore(LocalDateTime.now().plusDays(7))) {
this.startPrice = startPrice;
this.reservePrice = reservePrice;
this.closeDate = closeDate;
this.item = item;
this.highestBidder = highestBidder;
this.currentBid = currentBid;
this.seller = seller;
UP = currentBid * 0.20;
LOW = currentBid * 0.10;
} else {
throw new Exception("CloseDate error: " + closeDate.format(formatter));
}
}
public void auctionVictory() {
if (status == Status.CLOSED && currentBid >= reservePrice) {
User winner = getHighestBidder();
Item winnerItem = getItem();
winnerItem.getItemName(itemName);
winner.victories.add(itemName);
}
}
}
My Item Class:
public class Item {
private String itemName;
public Item(String itemName, User seller) {
setDescription(itemName);
}
public boolean checkItemSearch(String itemDescription) {
if (itemName.equals(itemDescription)) {
return true;
}
return false;
}
@Override
public String toString() {
return getItemName(itemName);
}
public void setDescription(String itemName) {
this.itemName = itemName;
}
public String getItemName(String itemName) {
return itemName;
}
}
My Buyer Class:
public final class Buyer extends User {
public static List<String> victories = new LinkedList<String>();
public void Victory() {
}
public Buyer(String username, String password) {
super(username, password);
}
}
I expect the method 'auctionVictory' to get the User with the highest bid and get the Item that was up for auction if the current bid is higher than the reserve price.
Once I get the Item and Buyer I want to call the getItemName method from the Item class and get the string name for this item. After it gets this I want to add this string to the 'victories' list in the Buyer class.