-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoanAccount.java
More file actions
36 lines (30 loc) · 1.08 KB
/
LoanAccount.java
File metadata and controls
36 lines (30 loc) · 1.08 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
public class LoanAccount extends Account {
private final double interestRate = 8.5;
public LoanAccount(String accountNumber, String holderName, double balance) {
super(accountNumber, holderName, balance);
}
@Override
public void showAccountType() {
System.out.println("Account Type: Loan Account (Interest Rate: " + interestRate + "%)");
}
@Override
public void deposit(double amount) {
if (amount <= 0) {
System.out.println("Error: Payment amount must be positive.");
return;
}
balance += amount;
System.out.println("₹" + amount + " paid toward loan.");
System.out.println("Remaining loan balance: ₹" + balance);
}
@Override
public void withdraw(double amount) {
if (amount <= 0) {
System.out.println("Error: Loan amount must be positive.");
return;
}
balance -= amount;
System.out.println("₹" + amount + " borrowed successfully.");
System.out.println("Total loan balance: ₹" + Math.abs(balance));
}
}