diff options
author | clarkohw <66530369+clarkohw@users.noreply.github.com> | 2021-04-16 12:28:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-16 12:28:06 -0400 |
commit | da1475f7e264fcd5902eb7bfd8482e64c1327fde (patch) | |
tree | f21fd8eebff038f7edfdb97791e3515754596f07 | |
parent | 607dd5c1289bb25fad8dfd599e99d3d9c751c96b (diff) | |
parent | 07f02ae891169a1906a2040e169099854f319aa3 (diff) |
Merge pull request #9 from cs0320-2021/trade-query-endpoint
fixed profit map
-rw-r--r-- | src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java | 16 |
1 files changed, 14 insertions, 2 deletions
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 |