-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDepositAccount.java
More file actions
44 lines (37 loc) · 1.22 KB
/
Copy pathDepositAccount.java
File metadata and controls
44 lines (37 loc) · 1.22 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
package labTask3;
class DepositAccount extends Account {
private int installmentsPaid;
private static final int TOTAL_INSTALLMENTS = 5;
public DepositAccount(double balance) {
super(balance);
this.installmentsPaid = 0;
}
public void payInstallment(double amount) {
deposit(amount);
installmentsPaid++;
System.out.println("Installment paid. (" + installmentsPaid + "/" + TOTAL_INSTALLMENTS + ")");
}
public void withdraw(double amount) {
if (installmentsPaid >= TOTAL_INSTALLMENTS) {
if (amount <= balance) {
balance -= amount;
System.out.println("Withdrawn: " + amount);
} else {
System.out.println("Insufficient balance.");
}
} else {
System.out.println("Cannot withdraw before 5 installments.");
}
}
public void deposit(double amount) {
balance += amount;
}
public boolean canTransferTo(Account toAccount) {
return false;
}
public void applyInterest() {
if (installmentsPaid >= TOTAL_INSTALLMENTS) {
balance += balance * 0.07;
}
}
}