-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
35 lines (27 loc) · 941 Bytes
/
Copy pathAccount.java
File metadata and controls
35 lines (27 loc) · 941 Bytes
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
package labTask3;
abstract class Account {
protected double balance;
public Account(double balance) {
this.balance = balance;
}
public abstract void withdraw(double amount);
public abstract void deposit(double amount);
public double getBalance() {
return balance;
}
public abstract boolean canTransferTo(Account toAccount);
public void transferTo(Account toAccount, double amount) {
if (!this.canTransferTo(toAccount)) {
System.out.println("Transfer not allowed from this account.");
return;
}
if (this.balance >= amount) {
this.withdraw(amount);
toAccount.deposit(amount);
System.out.println("Transfer successful.");
} else {
System.out.println("Not enough balance to transfer.");
}
}
public abstract void applyInterest();
}