-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsset.java
More file actions
73 lines (59 loc) · 1.96 KB
/
Asset.java
File metadata and controls
73 lines (59 loc) · 1.96 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
66
67
68
69
70
71
72
73
import java.util.Objects;
public class Asset {
private String id;
private double expectedReturn;
private double riskLevel;
private int maxQuantity;
private int allocatedQuantity;
public Asset(String id, double expectedReturn, double riskLevel, int maxQuantity) {
this.id = id;
this.expectedReturn = expectedReturn;
this.riskLevel = riskLevel;
this.maxQuantity = maxQuantity;
this.allocatedQuantity = 0;
}
public Asset(Asset original, int allocatedQuantity) {
this.id = original.id;
this.expectedReturn = original.expectedReturn;
this.riskLevel = original.riskLevel;
this.maxQuantity = original.maxQuantity;
this.allocatedQuantity = allocatedQuantity;
}
public String getId() {
return id;
}
public double getExpectedReturn() {
return expectedReturn;
}
public double getRiskLevel() {
return riskLevel;
}
public int getMaxQuantity() {
return maxQuantity;
}
public int getAllocatedQuantity() {
return allocatedQuantity;
}
public void setAllocatedQuantity(int allocatedQuantity) {
this.allocatedQuantity = allocatedQuantity;
}
@Override
public String toString() {
return id + ": " + allocatedQuantity + " units";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Asset asset = (Asset) o;
return Double.compare(asset.expectedReturn, expectedReturn) == 0 &&
Double.compare(asset.riskLevel, riskLevel) == 0 &&
maxQuantity == asset.maxQuantity &&
allocatedQuantity == asset.allocatedQuantity &&
Objects.equals(id, asset.id);
}
@Override
public int hashCode() {
return Objects.hash(id, expectedReturn, riskLevel, maxQuantity, allocatedQuantity);
}
}