I'm working on an assignment where I need to do some work with ArrayLists. I declare one ArrayList early on in my program as
static ArrayList<Double> prices = new ArrayList<>();
and I want to use this arraylist in an enhanced for loop in a method later on. Currently the code I have for this method is
public static double getTotal(ArrayList<Double> prices) {
double total = 0.0;
for (double value: prices){
total += (prices);
}
subTotal = total + (total * .0825); //add tax to get subTotal
return subTotal;
}
I am trying to get the value total to = the total from the previous iteration + each value in the ArrayList prices. I'm pretty sure that the way I have it programmed is not the correct way to do it, but I am totally stumped on how to get this to work. Any ideas? If you need further clarification on what I'm trying to do or if you need more excerpts from my code I'm happy to provide it. Thanks!
total += value
You should add the value, not the List.
Structure of a for each :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With