-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortfolio.java
More file actions
63 lines (50 loc) · 1.49 KB
/
Copy pathPortfolio.java
File metadata and controls
63 lines (50 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class Portfolio{
// instance variables - replace the example below with your own
private int sharesOwned;
private double cashOwned;
private int price;
HashMap<String,Integer>myStocks;
/**
* Constructor for objects of class Portfolio
*/
public Portfolio(){
// initialise instance variables
cashOwned = 750;
myStocks = new HashMap<>();
//initilise hashmap
myStocks.put("GOOGL", 0);
myStocks.put("APPL", 0);
myStocks.put("NYSE", 0);
myStocks.put("ETR", 0);
myStocks.put("AMZN", 0);
myStocks.put("PYPL", 0);
}
public HashMap<String,Integer> getMap() {
return myStocks;
}
public HashMap<String,Integer> setMap(HashMap<String,Integer> map) {
myStocks = map;
return map;
}
public int getShares(String company) {
sharesOwned = myStocks.get(company);
return sharesOwned;
}
public double getCash() {
return cashOwned;
}
public void setCash(double cash) {
cashOwned = cash;
}
public void setSharesBuy(String symbol, int sshares) {
sshares = myStocks.get(symbol) + sshares;
myStocks.replace(symbol, sshares);
}
public void setSharesSell(String symbol, int sshares) {
sshares = myStocks.get(symbol) - sshares;
myStocks.replace(symbol, sshares);
}
}