}
return aResponse;
}
public GenericResponse calculateAverageIncome(StatisticsDTO pStatistics) throws PersistenceException {
GenericResponse aResponse = new GenericResponse();
StatisticsDTO statistics = new StatisticsDTO();
List<UserDTO> theUsers = userFactory.findForIncomeStatistics(pStatistics);
double income = 0;
int avgIncome = 0;
if(theUsers != null && !theUsers.isEmpty()) {
for(UserDTO user : theUsers) {
income = income + user.getIncome();
}
avgIncome = (int)income/theUsers.size();
statistics.setAvgIncome(avgIncome);
aResponse.setStatistics(statistics);
aResponse.setResponseStatus(true);
}
else {
aResponse.setResponseStatus(false);
aResponse.setErrorMessage("No users found for given criteria");
}
return aResponse;
}