aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkohw <clark_oh-willeke@brown.edu>2021-04-16 12:25:57 -0400
committerclarkohw <clark_oh-willeke@brown.edu>2021-04-16 12:25:57 -0400
commit07f02ae891169a1906a2040e169099854f319aa3 (patch)
treeecae2eaa562a57acdf0e9b011f5c78332347210d
parent34c63585d8a07f1337e7dbd2e95735455abd1908 (diff)
fixed profit map
-rw-r--r--src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java16
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