-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
171 lines (145 loc) · 5.63 KB
/
Customer.java
File metadata and controls
171 lines (145 loc) · 5.63 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* Jay Jayewardene. A class that represents a customer */
public class Customer extends Object {
private Bond bond; //stores the bond instance for the customer
private Stock stock; //stores the stock value for the customer
private MutualFund mutualFund; //stores the mutual fund value for the customer
private CashAsset cashAsset; //stores the cash asset value for the customer
private CashAsset cashAccount; //stores the cash account value for the customer
private double commission; //stores the commission for the customer
private double commissionAmount; //stores the commission amount for the customer
/* A constructor that sets the customer's cash amount and the commission */
public Customer(CashAsset cashAsset, double commission) {
this.cashAsset = cashAsset;
this.commission = commission;
}
/* A constructor that sets the customer's cash asset, bond, stock, and commission */
public Customer(CashAsset cashAsset, Bond bond, MutualFund mutualFund, Stock stock, double commissionAmount) {
this.cashAsset = cashAsset;
this.bond = bond;
this.mutualFund = mutualFund;
this.stock = stock;
this.commissionAmount = commissionAmount;
}
/* get the bond instance that corresponds with the account */
public Bond getBond() {
return bond;
}
/* change the bond instance that corresponds with the account */
public void setBond(Bond bond) {
this.bond = bond;
}
/* get the mutual fund instance that corresponds with the account */
public MutualFund getMutualFund() {
return mutualFund;
}
/* change the mutual fund instance that corresponds with the account */
public void setMutualFund(MutualFund mutualFund) {
this.mutualFund = mutualFund;
}
/* get the stock instance that corresponds with the account */
public Stock getStock() {
return stock;
}
/* change the stock instance that corresponds with the account */
public void setStock(Stock stock) {
this.stock = stock;
}
/* get the cash account instance that corresponds with the account */
public CashAsset getCashAccount() {
return cashAccount;
}
/* change the cash account instance that corresponds with the account */
public void setCashAccount(CashAsset cashAccount) {
this.cashAccount = cashAccount;
}
/* get the commission amount instance that corresponds with the account */
public double getCommissionAmount() {
return commissionAmount;
}
/* change the commission amount instance that corresponds with the account */
public void setCommissionAmount(double commissionAmount) {
this.commissionAmount = commissionAmount;
}
/* take the sum of the bond value, mutual fund value, and stock value of the account if they exist */
public double currentValue() {
double value = cashAccount.getBalance();
double bondValue = 0;
double stockValue = 0;
double mutualFundValue = 0;
if (bond != null) {
bondValue = bond.getNumberOwned() * bond.getCurrentPrice();
}
if (mutualFund != null) {
mutualFundValue = mutualFund.getNumberShares() * mutualFund.getCurrentPrice();
}
if (stock != null){
stockValue = stock.getNumberShares() * stock.getCurrentPrice();
}
return bondValue + mutualFundValue + stockValue;
}
/* get the sum of the capital gains of the stock, mutual fund, and bond if they exist */
public double getCapitalGains() {
double capitalGainsStock = 0;
double capitalGainsMutualFund = 0;
double capitalGainsBond = 0;
if (stock != null) {
capitalGainsStock = stock.getCapitalGains();
}
if (mutualFund != null) {
capitalGainsMutualFund = mutualFund.getCapitalGains() ;
}
if(bond != null) {
capitalGainsBond = bond.getCapitalGains();
}
return capitalGainsStock + capitalGainsMutualFund + capitalGainsBond;
}
/* make a deposit by adding an amount of input to the balance of the cash account */
public void deposit (double amount) {
this.deposit(amount + cashAsset.getBalance());
}
/* call the withdraw method from the cash account with a boolean set as false */
public boolean withdraw(double input) {
return cashAccount.withdraw(input, false);
}
/* sell the bond */
public void sellBond() {
cashAccount.deposit(bond.sell());
}
/* buy the bond */
public boolean buyBond() {
if (bond.getCurrentPrice() > currentValue()) {
return false;
}
else {
return cashAsset.withdraw(bond.buy(), true);
}
}
/* pay the bond interest */
public void payBondInterest(){
cashAccount.deposit(bond.payInterest());
}
/* withdraw from mutual fund */
public void withdrawMutualFund(double withdrawAmount) {
cashAsset.deposit(mutualFund.sell(withdrawAmount));
}
/* buy mutual fund */
public boolean buyMutualFund(double buyAmount){
if (buyAmount > currentValue())
return false;
else {
return cashAsset.withdraw(mutualFund.buy(buyAmount), true);
}
}
/* sell stock shares */
public void sellStockShares(int numberOfShares) {
cashAsset.deposit(stock.sell(numberOfShares, getCommissionAmount()));
}
/* buy stock shares */
public boolean buyStockShares(int numberOfShares) {
if (stock.buy(numberOfShares, commission) > currentValue())
return false;
else {
return cashAsset.withdraw(stock.buy(numberOfShares, getCommissionAmount()), true);
}
}
}