-
Notifications
You must be signed in to change notification settings - Fork 0
/
SavingsAccount.java
144 lines (129 loc) · 4.82 KB
/
SavingsAccount.java
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
//Amir Fanous - 300008851
//Branko Malaver-Vojvodic - 300048455
import java.util.Date; /*lease refer to the CheckingAccount class for the comments since they are very similar classes, the only differences is the details in to String because its a different type of account
and the fees that change since this class doesnt have a checking fee and it has different inerest values but the rest is identical*/
public class SavingsAccount extends Account{
private double fees;
private String description;
private double interest;
private Date todaysdate;
private int size;
public final static byte DEPOSIT=0;
public final static byte WITHDRAW = 1;
public final static byte ADDEDINTEREST = 2;
public SavingsAccount(Customer customer, double balance){
super(customer, balance);
size=0;
}
public double deposit(double quantity){
todaysdate= new Date();
description="deposit of amount"+quantity;
setBalance(this.getBalance()+quantity);
if (size<transactions.length){
transactions[size] = new Transaction(DEPOSIT, quantity, todaysdate, fees, description);
size++;
}
else{
reallocate();
transactions[size] = new Transaction(DEPOSIT, quantity, todaysdate, fees, description);
size++;
}
return this.getBalance();
}
public double withdraw(double reduce){
todaysdate= new Date();
description="withdrawal of amount"+reduce;
if (reduce<=this.getBalance()){
fees=0;
setBalance(this.getBalance()-reduce-fees);
if (size<transactions.length){
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
else{
reallocate();
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
}
else if(getCustomer().canOverDraft(reduce-this.getBalance()) && this.getCustomer() instanceof Adult){
fees=getCustomer().getOverdraftPenalty();
setBalance(this.getBalance()-reduce-fees);
if (size<transactions.length){
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
else{
reallocate();
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
}
else if(!getCustomer().overDraftAmount(reduce-this.getBalance()) && getCustomer().canOverDraft(reduce-this.getBalance()) && this.getCustomer() instanceof Senior){
fees= getCustomer().getOverdraftPenalty();
setBalance(this.getBalance()-reduce-fees);
if (size<transactions.length){
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
else{
reallocate();
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
}
else if(getCustomer().overDraftAmount(reduce-this.getBalance()) && this.getCustomer() instanceof Senior){
fees= this.getCustomer().getOverdraftPenalty();
setBalance(this.getBalance()-reduce-fees);
if (size<transactions.length){
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
else{
reallocate();
transactions[size] = new Transaction(WITHDRAW, reduce, todaysdate, fees, description);
size++;
}
}
else{
System.out.println("You cannot overdraft this amount");
}
return this.getBalance();
}
public double addInterest(){
todaysdate= new Date();
if (this.getBalance()<0){
interest=0;
}
else{
interest=this.getCustomer().getSavingsInterest()*this.getBalance();
}
setBalance(this.getBalance()+interest);
if (size<transactions.length){
transactions[size] = new Transaction(ADDEDINTEREST, interest, todaysdate, fees, description);
size++;
}
else{
reallocate();
transactions[size] = new Transaction(ADDEDINTEREST, interest, todaysdate, fees, description);
size++;
}
return this.getBalance();
}
public String toString(){
String result;
if (getCustomer() instanceof Senior){
result = "The Senior: " + getCustomer() +"\nHas an account with the account number: " + getAccountNumber() + " \nThis account is of type Savings and has a balance of: " + getBalance()+"$";
}
else if (getCustomer() instanceof Adult){
result = "The Adult: " + getCustomer() +"\nHas an account with the account number: " + getAccountNumber() + " \nThis account is of type Savings and has a balance of: " + getBalance()+"$";
}
else if (getCustomer() instanceof Student){
result = "The Student: " + getCustomer() +"\nHas an account with the account number: " + getAccountNumber() + " \nThis account is of type Savings and has a balance of: " + getBalance()+"$";
}
else{
result = "The Customer: " + getCustomer() +"\nHas an account with the account number: " + getAccountNumber() + " \nThis account is of type Savings and has a balance of: " + getBalance()+"$";
}
return result;
}
}