Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. public static void getPerStore(ArrayList<Transaction> transactionArray) {
  2. HashMap<String, Double> storeTotals = new HashMap<>();
  3.  
  4. double min = 9999;
  5. double max = 0;
  6. double total = 0;
  7. double average = 0;
  8. for (Transaction transAct : transactionArray) {
  9. if (storeTotals.containsKey(Integer.toString(transAct.getStoreID()))) {
  10.  
  11. double value = (double) storeTotals.get(Integer.toString(transAct.getStoreID()));
  12. value += transAct.getValue();
  13.  
  14. if (max <= transAct.getValue()) {
  15. max = transAct.getValue();
  16. }
  17. if (min >= transAct.getValue()) {
  18. min = transAct.getValue();
  19. }
  20.  
  21. storeTotals.put(Integer.toString(transAct.getStoreID()), value);
  22. } else {
  23. storeTotals.put(Integer.toString(transAct.getStoreID()), transAct.getValue());
  24. }
  25. }
  26. System.out.println("Totals for each store");
  27. for (Map.Entry<String, Double> entry : storeTotals.entrySet()) {
  28.  
  29. System.out.println("Store ID: " + entry.getKey() + ", Total Value = " + entry.getValue());
  30. }
  31.  
  32. for (Map.Entry<String, Double> entry : storeTotals.entrySet()) {
  33. total += entry.getValue();
  34.  
  35. }
  36.  
  37. average = total / storeTotals.size();
  38. System.out.println("Total for all stores: " + total);
  39. System.out.println("Average: " + average);
  40. System.out.println("Highest transaction: " + max);
  41. System.out.println("Lowest transaction: " + min);
  42.  
  43. // return storeTotals;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement