while(!input.equals("-1")){
plantName = "";
plantCost = "";
colorOfFlowers = "";
isAnnual = false;
if (input.charAt(0) == 'p') {
Plant plant = new Plant();
String[] temp = input.split(" ");
plantName = temp[1];
plantCost = temp[2];
plant.setPlantName(plantName);
plant.setPlantCost(plantCost);
myGarden.add(plant);
}else {
Flower flower = new Flower();
String[] temp = input.split(" ");
flower.setPlantName(temp[1]);
flower.setPlantCost(temp[2]);
flower.setPlantType(Boolean.parseBoolean(temp[3]));
flower.setColorOfFlowers(temp[4]);
myGarden.add(flower);
}
input = scnr.nextLine();
}
Here's an example of what I mean. at the beginning of the if statement I created a plant object and it ended up making the program work how I wanted it to, I'm just not exactly sure why it worked. What Im thinking is that by creating the object inside of the while loop it "deletes" at the end of the loop and creates a new one.
Again though I'm not sure because everytime I ask my professor a question about any concept he tells me to come here and ask someone. Thanks in advance.