The program will not recognize that I have entered a value for gerbil.foodTypes (giving me a value of 0 for gerbil.foodName.length. Why?
class Gerbil {
public int foodTypes;
public String[] foodName = new String[foodTypes];
}
public class mainmethod {
public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
Gerbil gerbil = new Gerbil();
System.out.println("How many types of food do the gerbils eat?");
gerbil.foodTypes = keyboard.nextInt();
for (int x = 0; x < gerbil.foodTypes ; x++) {
System.out.println("Enter the name of food item " + (x+1));
gerbil.foodName[x] = keyboard.nextLine();
keyboard.nextLine();
System.out.println("Maximum consumed per gerbil:");
gerbil.foodMax[x] = keyboard.nextInt();
}