Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void getPerStore(ArrayList<Transaction> transactionArray) {
- HashMap<String, Double> storeTotals = new HashMap<>();
- double min = 9999;
- double max = 0;
- double total = 0;
- double average = 0;
- for (Transaction transAct : transactionArray) {
- if (storeTotals.containsKey(Integer.toString(transAct.getStoreID()))) {
- double value = (double) storeTotals.get(Integer.toString(transAct.getStoreID()));
- value += transAct.getValue();
- if (max <= transAct.getValue()) {
- max = transAct.getValue();
- }
- if (min >= transAct.getValue()) {
- min = transAct.getValue();
- }
- storeTotals.put(Integer.toString(transAct.getStoreID()), value);
- } else {
- storeTotals.put(Integer.toString(transAct.getStoreID()), transAct.getValue());
- }
- }
- System.out.println("Totals for each store");
- for (Map.Entry<String, Double> entry : storeTotals.entrySet()) {
- System.out.println("Store ID: " + entry.getKey() + ", Total Value = " + entry.getValue());
- }
- for (Map.Entry<String, Double> entry : storeTotals.entrySet()) {
- total += entry.getValue();
- }
- average = total / storeTotals.size();
- System.out.println("Total for all stores: " + total);
- System.out.println("Average: " + average);
- System.out.println("Highest transaction: " + max);
- System.out.println("Lowest transaction: " + min);
- // return storeTotals;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement