Create folder bankaccountquiz · dmakeroam/java@22e3fc6 · GitHub
Skip to content

Commit 22e3fc6

Browse files
author
Sirinat Paphatsirinatthi
committed
Create folder bankaccountquiz
1 parent e041b24 commit 22e3fc6

5 files changed

Lines changed: 206 additions & 0 deletions

File tree

‎bankaccountquiz/BankAccount.java‎

Lines changed: 90 additions & 0 deletions
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package bankaccountquiz;
2+
3+
/**
4+
*
5+
* @author Ares
6+
*/
7+
public class CurrentDepositAccount extends BankAccount {
8+
private static final String ACCTYPE="Current Deposit Account";
9+
private long linkSavingsAccount;
10+
11+
public CurrentDepositAccount() {
12+
}
13+
14+
@Override
15+
public String getAccType() {
16+
return CurrentDepositAccount.ACCTYPE;
17+
}
18+
19+
public long getLinkSavingsAccount() {
20+
return linkSavingsAccount;
21+
}
22+
23+
public void setLinkSavingsAccount(long linkSavingsAccount) {
24+
this.linkSavingsAccount = linkSavingsAccount;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return "CurrentDepositAccount{" +super.toString() + ", linkSavingsAccount=" + linkSavingsAccount + '}';
30+
}
31+
32+
}

‎bankaccountquiz/Customer.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package bankaccountquiz;
2+
/**
3+
*
4+
* @author Ares
5+
*/
6+
public class Customer {
7+
// do something
8+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package bankaccountquiz;
2+
3+
/**
4+
*
5+
* @author Ares
6+
*/
7+
public class SavingsAccount extends BankAccount {
8+
private static final String ACCTYPE="Savings Account";
9+
private double interestRate;
10+
private static double TRANSFER_FEE=20;
11+
12+
public SavingsAccount() {
13+
}
14+
15+
public double getInterestRate() {
16+
return interestRate;
17+
}
18+
19+
public void setInterestRate(double interestRate) {
20+
this.interestRate = interestRate;
21+
}
22+
23+
public void addInterest(){
24+
double balance=super.getBalance()*this.interestRate;
25+
super.deposit(balance);
26+
}
27+
28+
@Override
29+
public String getAccType(){
30+
return SavingsAccount.ACCTYPE;
31+
}
32+
33+
@Override
34+
public void transfer(BankAccount target, double amount) {
35+
if(target instanceof CurrentDepositAccount){
36+
CurrentDepositAccount tg=(CurrentDepositAccount)target;
37+
if(this.getAccId()==tg.getLinkSavingsAccount()){
38+
super.withdraw(amount+SavingsAccount.TRANSFER_FEE);
39+
target.deposit(amount);
40+
}
41+
else{
42+
super.withdraw(amount);
43+
target.deposit(amount);
44+
}
45+
}
46+
else{
47+
super.withdraw(amount);
48+
target.deposit(amount);
49+
}
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return "SavingsAccount{"+super.toString() + ", interestRate=" + interestRate + '}';
55+
}
56+
57+
58+
59+
}
Lines changed: 17 additions & 0 deletions

0 commit comments

Comments
 (0)