I've built a simple item class;
class itemInfo{
int auctionID;
int startPrice;
int buyoutPrice;
}
I've created an ArrayList;
ArrayList<itemInfo> itemSet = new ArrayList<itemInfo>();
I also have a method here that allows a user to create an item (the method is incomplete, I've only tried implementing choice == 1 so far!);
public void auctionChoice(){
System.out.println("---- What would you like to do? ----\n");
System.out.println("1: List an item for auction\n");
System.out.println("2: Bid on an existing item\n");
System.out.println("3: Remove an item from the auction\n");
if(scanner.next().equals("1")){
itemInfo createdItem = new itemInfo();
System.out.println("----Enter the auctionID----");
createdItem.auctionID = scanner.nextInt();
System.out.println("----Enter the item startPrice----");
createdItem.startPrice = scanner.nextInt();
System.out.println("----Enter the buyoutPrice----");
createdItem.buyoutPrice = scanner.nextInt();
System.out.println("Auction ID:" +createdItem.auctionID+ "\nstartPrice:" +createdItem.startPrice+ "\nbuyoutPrice:" +createdItem.buyoutPrice);
itemSet.add(createdItem);
}
}
What I am stuck on is building a method that will allow the user to view a list of current item auctions, basically a way to print out the itemSet ArrayList.
I have looked into using toString() but I am unsure of how to get it to return more than one value, i.e auctionID, startPrice, buyoutPrice.
Ideally I would like the user to select a choice such as "view current auctions" and then the method to print the entire ArrayList in a format such as "Auction ID: **** Start Price: **** Buyout Price: ****" with obviously the **** being the number the user inputted.