I created a list from a text document. I then created a loop to go through it and count every time "strawberry" is in it. But I'm not sure why, it is not working.
I know my list gets created correctly because my print statement at the end returns the correct value. But then it doesn't add up the flavors or the number of times strawberry is present.
import java.util.List;
import java.util.ArrayList;
public class IceCream {
public static void main(String[] args) {
int count, strawberry, average, i;
List<String> flavors = new ArrayList<String>();
TextIO.readFile("src/icecream.dat");
while (TextIO.eof() == false) {
flavors.add(TextIO.getln());
}
count = 0;
strawberry = 0;
for (i = 0; i < flavors.size(); i++); {
count++;
if ( flavors.equals("Strawberry")) {
strawberry++;
}
}
TextIO.putln(flavors.size());
average = strawberry / count * 100;
TextIO.putln("" + count + " ice cream cones were sold. "
+ strawberry + " were strawberry flavored, "
+ "which is a total of " + average + "% of the ice cream cones sold.");
}
}