So this is my first time posting here. I am trying to read data from a file, create multiple objects from that data, and then place the created objects into an ArrayList. But every time I have tried, I just get multiple copies of the same object, instead of different objects. I am at my wits end.
Anyways, here is the code for the method to read the data in from the file. Thanks in advance for any help!
public void openShop() throws IOException{
System.out.println("What is the name of the shop?");
shopName = keyboard.nextLine();
setShopFile();
File openShop = new File(shopFile);
if (openShop.isFile()){
Scanner shopData = new Scanner(openShop);
shopName = shopData.nextLine();
shopOwner = shopData.nextLine();
while (shopData.hasNextLine()){
shopItem.setName(shopData.nextLine());
shopItem.setPrice(Double.parseDouble(shopData.nextLine()));
shopItem.setVintage(Boolean.parseBoolean(shopData.nextLine()));
shopItem.setNumberAvailable(Integer.parseInt(shopData.nextLine()));
shopItem.setSellerName(shopData.nextLine());
shopInventory.add(shopItem);
}
setNumberOfItems();
}
else
System.out.println("That shop does not exist. Please try to open" +
"the shop again.");
isSaved = true;
}