Hello there,
I need some help working with arrays and loops. i have a set of records that contains different actions. i need to iterate over the records, check the actions per record, and do some calculations based on the actions. so for example if 1 record have one action, the calculation is performed once, if another record have 2 actions, the calculation is performed twice. The issue i have is adding the total calculated sum of the actions per record. Currently, the program is totaling the result of the first record twice. i want it to total per record, please find below my current code. any advice on this is greatly appreciated. thanks
I need some help working with arrays and loops. i have a set of records that contains different actions. i need to iterate over the records, check the actions per record, and do some calculations based on the actions. so for example if 1 record have one action, the calculation is performed once, if another record have 2 actions, the calculation is performed twice. The issue i have is adding the total calculated sum of the actions per record. Currently, the program is totaling the result of the first record twice. i want it to total per record, please find below my current code. any advice on this is greatly appreciated. thanks
Code:
ArrayList<Double> fixityCheckCost = new ArrayList<Double>();
if (action.getActionType().equals(ActionType.FIXITYCHECK) && action.getTrigger().equals(Trigger.ON_TIME))
{
FixityPlugin fixityPlugin = (FixityPlugin) psiList.get(0).getPluginService().getPlugin();
System.out.println(aggregationActions.getAggregation().getId() + " Aggregation Actions: " + fixityPlugin.getProcessingCostPerHour());
double fixityProcessingCostPerH = fixityPlugin.getProcessingCostPerHour();
double result = fixityProcessingCostPerH * 2.0;
System.out.println (fixityPlugin.getAlgorithm() + " result is " + result);
fixityCheckCost.add(result);
double sum = 0.0;
for (int i = 0; i < fixityCheckCost.size(); i++)
{
sum += fixityCheckCost.get(i);
i++;
System.out.println(fixityPlugin.getAlgorithm() + " TOTAL IS " + sum);
//System.out.println(sum);
}
}
Comment