I'm not sure if I'm wording this correctly. I have an array policies[10], it can hold 10 floats.
I have a method that adds a float to the array when it's initialized. I have another method that totals up all the floats in the array together. The thing is that when I only have 3/10 of the array filled up, I get a null error. Can someone show me how I can fix this?
policies is a list of a class, Policy.
public float totalCoverage(){
float total = 0;
for (Policy x : policies){
total += x.amount;
}
return total;
}
For my test, I have 3/10 arrays, if i change the array size from 10 to 3, it works.
x.amount