aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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