Question: Hey folks, I ' m back with another question. I have a lab activity for school working with arrays. The error I ' m getting

Hey folks, I'm back with another question. I have a lab activity for school working with arrays. The error I'm getting is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 at PlantArrayListExample.main(PlantArrayListExample.java:34)
There are two other files in this project, a plant file and a flower file, so I could post the code from those if needed but it looks like the issue is in this one specifically.
The goal is, if the input is:
plant Spirea 10
flower Hydrangea 30 false lilac
flower Rose 6 false white
plant Mint 4-1
The output will be: (the printing formatting has been done on the other two files, flower.java and plant.java)
Plant Information:
Plant name: Spirea
Cost: 10 Plant Information:
Plant name: Hydrangea
Cost: 30
Annual: false
Color of flowers: lilac
Plant Information:
Plant name: Rose
Cost: 6
Annual: false
Color of flowers: white
Plant Information:
Plant name: Mint
Cost: 4
Any ideas on where I went wrong with this code? I searched Google and have revised/changed my code based off of other's solutions and answers multiple times now but I've gotten errors every time and this seems to be the closest I've gotten to results.
```
import java.util.Scanner;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class PlantArrayListExample {
// method to print an ArrayList of plant (or flower) objects
public static void PrintArrayList(ArrayList myGarden){
for(int i=0; i myGarden = new ArrayList();
// Declaring variables - plantName, plantCost, colorOfFlowers, isAnnual
String plantName;
Double plantCost;
String colorOfFlowers;
Boolean isAnnual;
input = scnr.next();
while(!input.equals("-1")){
``````
import java.util.Scanner;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class PlantArrayListExample {
// method to print an ArrayList of plant (or flower) objects
public static void PrintArrayList(ArrayList myGarden){
for(int i=0; i myGarden = new ArrayList();
// Declaring variables - plantName, plantCost, colorOfFlowers, isAnnual
String plantName;
Double plantCost;
String colorOfflowers;
Boolean isAnnual;
input = scnr.next();
while(!input.equals("-1")){
String[] info = input.split(""); // splitting input
if(info[0].toLowerCase().equals("plant")){// check if plant or flower and add to array
Plant pObj = new Plant();
pObj.setPlantName(info[1]);
pObj.setPlantCost(info[2]);
myGarden.add(pObj);
}
else{
Flower fObj = new Flower();
fObj.setPlantName(info[1]);
fObj.setPlantCost(info[2]);
fObj.setColorOfFlowers(info[4]);
fObj.setPlantType(Boolean.parseBoolean(info[3]));
myGarden.add(fObj);
}
input = scnr.next();
}
// Call the method printArrayList to print myGarden
PrintArrayList(myGarden);
}
}
```
Hey folks, I ' m back with another question. I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!