I am making a program where I am inputting the number of cows that I am going to input on the first line. Then I am inputting the cow name, a space, and then a number (ie:Bessie 4) on each successive line, where I am using a delimiter to parse the string into the name and the number, then putting it into an array. After that, if the first cow name is Bessie, then I am adding the associated number value to the first position of another array, called amountOfMilk, thereby changing the array value. But when I input Bessie 4, Bessie 5, and Bessie 6 on three different lines the amountOfMilk array is [0,0,0,0,0,0,0] when it should be [15,0,0,0,0,0,0].
int[] amountOfMilk = new int[7];
Scanner s = new Scanner(System.in);
int numberOfLogInputs = s.nextInt();
s.nextLine();
for(int i = 0; i < numberOfLogInputs; i++) {
String cowName = s.nextLine();
String delimiter = "[ ]";
String[] tokens = cowName.split(delimiter);
if(tokens[0] == "Bessie") {
amountOfMilk[0] += Integer.parseInt(tokens[1]);
}
}
System.out.println(Arrays.toString(amountOfMilk));