-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCashAsset.java
More file actions
110 lines (91 loc) · 3.57 KB
/
CashAsset.java
File metadata and controls
110 lines (91 loc) · 3.57 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
/* Jay Jayewardene. A class that represents money reserves */
public class CashAsset extends Object {
private double balance; // stores the balance of the cash asset
private double savingsRate; // stores the savings rate of the cash asset
private double loanRate; // stores the loan rate of the cash asset
private double loanLimit; // stores the loan limit of the cash asset
private double overdraftPenalty; //stores the overdraft penalty of the cash asset
private double deposit; //stores the deposit of the cash asset
private double accruedInterest; //stores the accreud interest of the cash asset
private boolean withdrawal; //stores the withdrawal of the cash asset
/* A constructor that sets the cash asset savings rate, interest rate for loans, the loan limit, and overdraft
* penalty */
public CashAsset(double savingsRate, double loanRate, double loanLimit, double overdraftPenalty) {
this.savingsRate = savingsRate;
this.loanRate = loanRate;
this.loanLimit = loanLimit;
this.overdraftPenalty = overdraftPenalty;
}
/* get the balance of the cash account */
public double getBalance() {
return balance;
}
/* get the savings rate of the cash account */
public double getSavingsRate() {
return savingsRate;
}
/* change the savings rate of the cash account */
public void setSavingsRate(double savingsRate) {
this.savingsRate = savingsRate;
}
/* get the loan rate of the cash account */
public double getLoanRate() {
return loanRate;
}
/* sets the loan rate of the cash account */
public void setLoanRate(double loanRate) {
this.loanRate = loanRate;
}
/*get the loan limit of the cash account */
public double getLoanLimit() {
return loanLimit;
}
/* change the loan limit for the cash account */
public void setLoanLimit(double loanLimit) {
this.loanLimit = loanLimit;
}
/* get the overdraft penalty for the cash account */
public double getOverdraftPenalty() {
return overdraftPenalty;
}
/* change the overdraft penalty for the cash account */
public void setOverdraftPenalty(double overdraftPenalty) {
this.overdraftPenalty = overdraftPenalty;
}
/* makes a deposit */
public void deposit (double amount) {
balance = getBalance() + amount;
}
/* makes a withdrawal */
public boolean withdraw(double input, boolean overdraft) {
if ((overdraft == false) && (input > getBalance())) {
return false; }
else {
balance = getBalance() - input;
return true;
}
}
/* represents a process day that changes the accrued interest */
public void processDay() {
if (balance > 0) {
setAccruedInterest ((getBalance() * (getSavingsRate()/365)) + getAccruedInterest());
}
else {
setAccruedInterest(-1 * (getBalance() * (getLoanRate()/365))+ getAccruedInterest());
}
}
/* represents the process month */
public void processMonth() {
if ((getBalance() + getAccruedInterest() < 0) && (getBalance() + getAccruedInterest() > getLoanLimit())) {
balance = getBalance() - getOverdraftPenalty();
}
}
/* get the accrued interest of the cash asset */
public double getAccruedInterest() {
return accruedInterest;
}
/* change the accrued interest of the cash asset */
protected void setAccruedInterest(double input) {
this.accruedInterest = accruedInterest;
}
}