From 07f02ae891169a1906a2040e169099854f319aa3 Mon Sep 17 00:00:00 2001 From: clarkohw Date: Fri, 16 Apr 2021 12:25:57 -0400 Subject: fixed profit map --- .../brown/cs/student/term/profit/ProfitCalculation.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main/java/edu/brown/cs') diff --git a/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java index 85b2a9a..4b59aae 100644 --- a/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java +++ b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java @@ -361,17 +361,18 @@ public class ProfitCalculation { while (rs.next()) { int id = rs.getInt("holder_id"); this.person = rs.getString("holder_name"); + resetClass(); + double gain = this.calculateGains(); if (moneyInput == 0) { profitMap.put(id, 0.0); } else { - profitMap.put(id, this.calculateGains() / moneyInput); + profitMap.put(id, gain / moneyInput); } } } catch (SQLException throwables) { System.out.println("ERROR: SQl error in profit calculation"); } - System.out.println(profitMap.toString()); return profitMap; } @@ -379,6 +380,17 @@ public class ProfitCalculation { return this.moneyInput; } + private void resetClass() { + tablesFilled = false; + moneyInput = 0; + buyHistoryMap = new HashMap<>(); + sellHistoryMap = new HashMap<>(); + realizedGainsMap = new HashMap<>(); + unrealizedGainsMap = new HashMap<>(); + currentStockPrices = new HashMap<>(); + tablesFilled = false; + } + public void setConnection(String filename) throws SQLException, ClassNotFoundException { // Initialize the database connection, turn foreign keys on -- cgit v1.2.3-70-g09d2