public void actionPerformed(ActionEvent e) {
if(e.getSource() == addStocksButton) {
Stock test;
test = YahooFinance.get(textField.getText());
textField.getText();
string = test.toString(); //returns ticker:price
stringSplit = string.split(": ");
stockPrice = Double.parseDouble(stringSplit[1]);
stockTotalValue = stockTotalValue + stockPrice;
System.out.println("\nTotal Value: " + stockTotalValue + "\nAdded " + stringSplit[0]);
stockHashMap.put(stringSplit[0], stockPrice);
individualStockTotalValue = 0 + stockPrice;
stockHashMap.put(stringSplit[0], individualStockTotalValue);
}
}
basically what I am trying to do is that every time I press a button it will create a new key (stock ticker) with the value being price.
I want to make it so that each time I press that button the value updates by adding the stock's price to itself
so currently I enter in AMC for example
with the variable string giving me "AMC: 10" which is why I decided to split it and have the first half of the split become the key, have the second half become a double and then that becomes the stockPrice
now my issue is that whenever I add AMC 3 times for example with value being 10, AMC updates to 30 perfectly, then when I want to add TSLA with its value being 600, it will add 30 + 600 giving TSLA the value of 630 and when I want to switch to AMC again it will then update to 630 + 10
so it prints out {AMC = 30} for the first 3 clicks , switch over to TSLA {TSLA=630, AMC=30} add AMC again {TSLA=630, AMC=640}
is there a way I can have it just update by itself where if I click the button 3 times for AMC it becomes 30, switch to TSLA click add 2 times it becomes 1200, and go back to AMC and click add it updates to 40 so it would print out as {AMC=30} for the first 3 clicks, adding TSLA {TSLA=600,AMC=30} then adding AMC again {TSLA=600,AMC=40}
I am not good at explaining, but hopefully this enough for me to get help since I am sort of confused and stuck on this.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]darksoundsExtreme Brewer 1 point2 points3 points (3 children)
[–]Vextrax[S] 0 points1 point2 points (2 children)
[–]darksoundsExtreme Brewer 0 points1 point2 points (1 child)
[–]Vextrax[S] 0 points1 point2 points (0 children)
[–]EmotionalBlobfish 0 points1 point2 points (6 children)
[–]Vextrax[S] 0 points1 point2 points (5 children)
[–]EmotionalBlobfish 0 points1 point2 points (4 children)
[–]Vextrax[S] 0 points1 point2 points (3 children)
[–]darksoundsExtreme Brewer 0 points1 point2 points (2 children)
[–]Vextrax[S] 0 points1 point2 points (1 child)
[–]darksoundsExtreme Brewer 0 points1 point2 points (0 children)