-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrader.java
More file actions
65 lines (49 loc) · 1.69 KB
/
Trader.java
File metadata and controls
65 lines (49 loc) · 1.69 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
63
64
65
package com.company;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
public class Trader {
double funds;
String name;
HashMap<String, Integer> holdings;
Trader(String name, double funds, HashMap<String, Integer> holdings) {
this.name = name;
this.funds = funds;
this.holdings = holdings;
}
public double getFunds() {
return funds;
} //to get funds of trader
public String getName() {
return name;
} //to get the name of trader
public HashMap<String, Integer> getHoldings() {
return holdings;
} //to get the holdings of trader
public void setFunds(double funds) {
this.funds = funds;
} //to set funds of trader
public void setName(String name) {
this.name = name;
} //to set the name of trader
@Override
public String toString() {
return "name= " + name + ",funds= " + funds + ",holdings= " + holdings;
}
public HashMap<String, Integer> createHashMap(String string) {
HashMap<String, Integer> hashMap = new HashMap<>();
if (string.endsWith("None")) {
} else {
String holdings = string.substring(string.indexOf("{") + 1, string.indexOf("}"));
String[] holdingsSplit = holdings.split("[,: ]");
for (int i = 0; i < holdingsSplit.length; i++) {
if (holdingsSplit[i].length() == 0)
continue;
else {
hashMap.put(holdingsSplit[i], Integer.parseInt(holdingsSplit[++i]));
}
}
}
return hashMap;
}
}