losing my mind looking for the issue with my method here. the goal is to take an arraylist of different times and amounts, turn it into a speed (time/amount) and then get the average speed of all the items in the arraylist, and continue to do that for each matching task in the arraylist.
here is my code:
if(history.size()>0){
for(CalcTasks c: calcTasks){
String currentTask = c.getTask();
double totalToAverage = 0;
int counter = 0;
for(WorkerHistory w: history){
if(w.getTask().equals(currentTask)){
int time = (w.getTimeTaken());
if (time == 0){
continue;
}
int amount = w.getAmount();
double timePerAmount = (double) (time/amount+totalToAverage);
totalToAverage = timePerAmount;
counter++;
String strCount = Integer.toString(counter);
Log.d("myappcounter", strCount);
}
}
if(counter != 0) {
double averageMinutesPerAmount = totalToAverage / counter;
double totalTaskTimeHours = ((c.getAmount() * averageMinutesPerAmount)/60d);
calcTaskAverages.add(new CalcTaskAverages(currentTask, averageMinutesPerAmount, totalTaskTimeHours, c.getAmount()));
String strAvg = Double.toString(calcTaskAverages.get(0).getAverageAnHour());
Log.d("mytaskAverages",strAvg);
double intermediate = totalTime + totalTaskTimeHours;
totalTime = intermediate;
}
}
I have two 2 items in the arraylist. one is time=100, amount=100 and the other time= 100, amount = 200. this should give me an average speed of 0.75 but the log.d at the end is printing a average of 0.5. I'd appreciate any input you can give :)