-
Notifications
You must be signed in to change notification settings - Fork 0
/
SavingAccounts.java
69 lines (57 loc) · 1.92 KB
/
SavingAccounts.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
package com.withWahib;
public class SavingAccounts extends BankAccount{
private String accountType;
private static double interestRate = 1.5;
public SavingAccounts(double interestRate,int accountNumber){
super(accountNumber);
}
public SavingAccounts(int accountNumber, double interestRate) {
super(accountNumber);
this.interestRate=interestRate;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}
public String getAccountType() {
return this.accountType;
}
public double getInterestRate() {
return this.interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public double calcInterest() {
return balance * interestRate;
}
@Override
public void deposit(double amount) {
if( amount > 0) {
balance += amount;
System.out.printf("Amount %.2f deposited%n", amount);
// Apply Transaction Fee
System.out.printf("Current Balance is: %.2f%n", balance);
} else {
System.out.println("A negative amount cannot be deposited");
}
}
@Override
public void withdraw(double amount) {
if(amount > 0) {
// Check sufficient balance
if((amount+interestRate) <= balance) {
System.out.printf("Amount of %.2f withdrawn from Account%n", amount);
balance -= amount;
System.out.printf("Current Balance is: %.2f%n", balance);
}
} else {
System.out.println("Negative amount cannot be withdrawn!");
}
}
@Override
public String toString() {
return super.toString()+"SavingAccounts{" +
"accountType='" + accountType + '\'' +
'}';
}
}