title: Using the ArrayList<Object> feature to store Array from Method
body: <p>I am about 95% done I believe, the only thing that is stopping me is that I have to print the results from printInfo() into an element.</p>
  <p>The program is gathering input, and the input is based on whether or not the item is a plant. After the input is entered and the setters are ran, I am suppose to access the
  printInfo() from plant for example, and store it as an element in the myGarden array.</p>
  <p>Then I will call a method that prints the elements of the object array. Those elements will be the information from printInfo() from the plant, and the flower class.</p>
  <p>update: I removed casting and simply changed  to , Modified the method as well. Remove the print command since it won't work for what we are trying to do and instead assign myGarden.get(i) to call upon the elements.</p>
  <pre><code>    package labpackage;
  
  import java.util.Scanner;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  public class PlantArrayListExample  {
  
     // TODO: Define a printArrayList method that prints an ArrayList of plant (or flower) objects 
  
      public static void printArrayList(ArrayList&lt;Plant&gt; myGarden) {
          
          
          
          
          for (int i = 0; i &lt; myGarden.size(); ++i) {
                 myGarden.get(i).printInfo();
              }
      
      
          }
     
     public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String input;
        
        
        
        
        // TODO: Declare an ArrayList called myGarden that can hold object of type plant
        
        ArrayList&lt;Object&gt; myGarden = new ArrayList&lt;&gt;();
        
     // TODO: Declare variables - plantName, plantCost, colorOfFlowers, isAnnual
        
        String plantName;
        String plantCost;
        String colorOffFlowers;
        boolean isAnnual;
        
        
        
        input = scnr.next();
        while(!input.equals(&quot;-1&quot;)){
           // TODO: Check if input is a plant or flower
            
            if (input.contains(&quot;plant&quot;)) { 
                
                Plant plant = new Plant();
            
                plantName = scnr.next();
                
                plantCost = scnr.next();
               
                plant.setPlantName(plantName);
                plant.setPlantCost(plantCost);
                System.out.println();
                
                myGarden.add(plant);
                
            // missing code to add print result as an element                 
          
            }
            
            if (!input.contains(&quot;plant&quot;)) { 
                
                Flower flower = new Flower();
                
                plantName = scnr.next();
                plantCost = scnr.next();
                isAnnual = scnr.nextBoolean();
                colorOffFlowers = scnr.next();
                
                
                
                
                flower.setPlantName(plantName);
                flower.setPlantCost(plantCost);
                flower.setPlantType(isAnnual);
                flower.setColorOfFlowers(colorOffFlowers);
                System.out.println();
  
                // missing code to add print result as an element 
                myGarden.add(flower);
            }
            
          
        
           input = scnr.next();
        }
        
        // TODO: Call the method printArrayList to print myGarden
        
        printArrayList(myGarden);
        
     }
  
  
  
  }
  
  
  
  package labpackage;
  
  public class Plant {
         protected String plantName;
         protected String plantCost;
  
         public void setPlantName(String userPlantName) {
            plantName = userPlantName;
         }
  
         public String getPlantName() {
            return plantName;
         }
  
         public void setPlantCost(String userPlantCost) {
            plantCost = userPlantCost;
         }
  
         public String getPlantCost() {
            return plantCost;
         }
  
         public void printInfo() {
            System.out.println(&quot;Plant Information: &quot;);
            System.out.println(&quot;   Plant name: &quot; + plantName);
            System.out.println(&quot;   Cost: &quot; + plantCost);
         }
      }
  
  package labpackage;
  
  public class Flower extends Plant {
  
         private boolean isAnnual;
         private String colorOfFlowers;
  
         public void setPlantType(boolean userIsAnnual) {
            isAnnual = userIsAnnual;
         }
  
         public boolean getPlantType(){
            return isAnnual;
         }
  
         public void setColorOfFlowers(String userColorOfFlowers) {
            colorOfFlowers = userColorOfFlowers;
         }
  
         public String getColorOfFlowers(){
            return colorOfFlowers;
         }
         
         @Override
         public void printInfo(){
            System.out.println(&quot;Plant Information: &quot;);
            System.out.println(&quot;   Plant name: &quot; + plantName);
            System.out.println(&quot;   Cost: &quot; + plantCost);
            System.out.println(&quot;   Annual: &quot; + isAnnual);
            System.out.println(&quot;   Color of flowers: &quot; + colorOfFlowers);
         }
      }
  </code></pre>