-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDAccount.java
More file actions
80 lines (73 loc) · 2.3 KB
/
Copy pathCDAccount.java
File metadata and controls
80 lines (73 loc) · 2.3 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
//1601890
//Ramy fekry
public class CDAccount extends Account{
private double mature;
private int duration;
private double CDAnnualInterestRate;
public CDAccount() {
setCDAnnualInterestRate();
}
public CDAccount(int id, double balance, int duration) {
setId(id);
setBalance(balance);
setDuration(duration);
setCDAnnualInterestRate();
}
public void setDuration(int duration) {
this.duration = duration;
}
public int getDuration() {
return this.duration;
}
public double getMatureBalance() {
mature = getBalance() * (Math.pow(1 + getMonthlyInterestRate(), duration));
return mature;
}
private void setCDAnnualInterestRate() {
this.CDAnnualInterestRate = super.getAnnualInterestRate() + (getDuration()/3 * 0.005);
}
public double getCDAnnualInterestRate() {
return this.CDAnnualInterestRate;
}
@Override
public double getMonthlyInterestRate() {
return CDAnnualInterestRate / 12;
}
@Override
public double getMonthlyInterest() {
double RDouble = getBalance() * getMonthlyInterestRate();
return RDouble;
}
@Override
public final void withdraw(double amount) {
System.out.println("you cannot withdraw from a CD Account");
}
@Override
public final void deposit(double amount) {
System.out.println("you cannot deposit from a CD Account");
System.out.println("=================================================================================================");
}
@Override
public String toString(){
System.out.println("Account Number Initial Balance Mature Balance Rate Date Created");
String TheOutput = String.format("%14d%21.1f%20.2f%10.2f%34s", getId(), getBalance(), getMatureBalance(), getCDAnnualInterestRate()*100,getDateCreated());
return TheOutput;
}
public void displayMonthlyInterests() {
double newBalance;
for(int i = 0; i < duration;i++) {
newBalance = getBalance() * (Math.pow(1 + getMonthlyInterestRate(), i+1));
System.out.print("Month " + (i+1) + " ");
System.out.printf("%10.2f\n", newBalance);
}
System.out.println("=================================================================================================");
}
@Override
public boolean equals(Object o){
if (o instanceof CDAccount){
CDAccount a = (CDAccount)o;
return (this.getId() == a.getId());
}
return false;
}
}