-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
46 lines (39 loc) · 1.33 KB
/
Account.java
File metadata and controls
46 lines (39 loc) · 1.33 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
45
46
public abstract class Account implements AccountOperations {
protected String accountNumber;
protected String holderName;
protected double balance;
public Account(String accountNumber, String holderName, double balance) {
this.accountNumber = accountNumber;
this.holderName = holderName;
this.balance = balance;
}
public abstract void showAccountType();
@Override
public void deposit(double amount) {
if (amount <= 0) {
System.out.println("Error: Deposit amount must be positive.");
return;
}
balance += amount;
System.out.println("₹" + amount + " deposited successfully.");
System.out.println("New balance: ₹" + balance);
}
@Override
public void withdraw(double amount) {
if (amount <= 0) {
System.out.println("Error: Withdrawal amount must be positive.");
return;
}
if (balance >= amount) {
balance -= amount;
System.out.println("₹" + amount + " withdrawn successfully.");
System.out.println("Remaining balance: ₹" + balance);
} else {
System.out.println("Insufficient funds! Current balance: ₹" + balance);
}
}
@Override
public double getBalance() {
return balance;
}
}