import java.util.ArrayList; import java.util.Scanner; public class GardenManager{ private ArrayList myGarden; public GardenManager(){ myGarden = new ArrayList(); } public ArrayList getMyGardenList(){ return myGarden; } public void addPlant(Plant plant){ myGarden.add(plant); } public Plant makePlant(String name, String cost){ Plant plant = new Plant(); plant.setPlantName(name); plant.setPlantCost(cost); return plant; } public Flower makeFlower(String name, String cost, String isAnnual, String color){ Flower flower = new Flower(); flower.setPlantName(name); flower.setPlantCost(cost); if (isAnnual.equals("false")){ flower.setPlantType(false); } else{ flower.setPlantType(true); } flower.setColorOfFlowers(color); return flower; } public ArrayList inputPlants(Scanner scnr){ String pName, pCost, pColor, isAnnual; String s; String[] splitString; Plant currPlant; ArrayList garden = new ArrayList(); while(true){ //plant has name and cost 3 inputs //flower has all 5 inputs System.out.println("Please enter your plant: "); System.out.println("type name cost (annual) (color)"); s = scnr.nextLine(); splitString = s.split(" "); //Check for exit if (splitString[0].equals("-1")){break;} //Check if too many words or too few words if (splitString.length > 5) { System.out.println("Too many words!!!"); continue; } else if ((splitString.length !=3) && (splitString.length !=5)){ System.out.println("Expecting 3 or 5 words!; -1 to quit"); continue; } //Set generic strings to vars for readability pName = splitString[1]; pCost = splitString[2]; // Plants take 3 if (splitString.length == 3){ currPlant = makePlant(pName, pCost); } // Flowers take 5 else{ //get remaining strings isAnnual = splitString[3]; pColor = splitString[4]; currPlant = makeFlower(pName, pCost, isAnnual, pColor); } addPlant(currPlant); System.out.println(); } return garden; } }