2024-09-14 09:33:00 +05:30
|
|
|
// Account class
|
|
|
|
class Account {
|
|
|
|
private String customerName;
|
|
|
|
private int accountNumber;
|
|
|
|
private double balance;
|
|
|
|
private String accountType;
|
|
|
|
|
|
|
|
public Account(String customerName, int accountNumber, double balance, String accountType) {
|
|
|
|
this.customerName = customerName;
|
|
|
|
this.accountNumber = accountNumber;
|
|
|
|
this.balance = balance;
|
|
|
|
this.accountType = accountType;
|
|
|
|
}
|
2024-09-14 01:50:46 +05:30
|
|
|
|
2024-09-14 09:37:06 +05:30
|
|
|
protected double getBalanceInternal() {
|
|
|
|
return balance;
|
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public void deposit(double amount) {
|
|
|
|
balance += amount;
|
|
|
|
}
|
2024-09-14 01:50:46 +05:30
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public void withdraw(double amount) {
|
|
|
|
balance -= amount;
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public double getBalance() {
|
|
|
|
return balance;
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public String getAccountType() {
|
|
|
|
return accountType;
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
// SavingsAccount class
|
|
|
|
class SavingsAccount extends Account {
|
|
|
|
private double interestRate;
|
2024-09-14 01:50:46 +05:30
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public SavingsAccount(String customerName, int accountNumber, double balance, double interestRate) {
|
|
|
|
super(customerName, accountNumber, balance, "Savings");
|
|
|
|
this.interestRate = interestRate;
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public void computeInterest() {
|
2024-09-14 09:37:06 +05:30
|
|
|
double interest = getBalanceInternal() * interestRate / 100;
|
2024-09-14 09:33:00 +05:30
|
|
|
deposit(interest);
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public void withdraw(double amount) {
|
2024-09-14 09:37:06 +05:30
|
|
|
if (amount > getBalanceInternal()) {
|
2024-09-14 09:33:00 +05:30
|
|
|
System.out.println("Insufficient balance");
|
|
|
|
} else {
|
|
|
|
super.withdraw(amount);
|
|
|
|
}
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
// CurrentAccount class
|
|
|
|
class CurrentAccount extends Account {
|
|
|
|
private double minimumBalance;
|
|
|
|
private double serviceTax;
|
2024-09-14 01:50:46 +05:30
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public CurrentAccount(String customerName, int accountNumber, double balance, double minimumBalance, double serviceTax) {
|
|
|
|
super(customerName, accountNumber, balance, "Current");
|
|
|
|
this.minimumBalance = minimumBalance;
|
|
|
|
this.serviceTax = serviceTax;
|
|
|
|
}
|
2024-09-14 01:50:46 +05:30
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public void checkMinimumBalance() {
|
2024-09-14 09:37:06 +05:30
|
|
|
if (getBalanceInternal() < minimumBalance) {
|
2024-09-14 09:33:00 +05:30
|
|
|
withdraw(serviceTax);
|
|
|
|
System.out.println("Service tax imposed");
|
|
|
|
}
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
|
2024-09-14 09:33:00 +05:30
|
|
|
public void withdraw(double amount) {
|
2024-09-14 09:37:06 +05:30
|
|
|
if (amount > getBalanceInternal()) {
|
2024-09-14 09:33:00 +05:30
|
|
|
System.out.println("Insufficient balance");
|
2024-09-14 01:50:46 +05:30
|
|
|
} else {
|
2024-09-14 09:33:00 +05:30
|
|
|
super.withdraw(amount);
|
|
|
|
checkMinimumBalance();
|
2024-09-14 01:50:46 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-09-14 09:33:00 +05:30
|
|
|
|
|
|
|
// Main function
|
|
|
|
public class AccountManagement {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
SavingsAccount saurabhAccount = new SavingsAccount("Saurabh", 1234, 10000, 5);
|
|
|
|
CurrentAccount akhilAccount = new CurrentAccount("Akhil", 5678, 5000, 1000, 500);
|
|
|
|
|
2024-09-14 09:37:06 +05:30
|
|
|
System.out.println("Initial balances:");
|
2024-09-14 09:33:00 +05:30
|
|
|
System.out.println("Saurabh's balance: " + saurabhAccount.getBalance());
|
2024-09-14 09:37:06 +05:30
|
|
|
System.out.println("Akhil's balance: " + akhilAccount.getBalance());
|
|
|
|
|
|
|
|
saurabhAccount.deposit(5000);
|
|
|
|
System.out.println("Saurabh's balance after deposit: " + saurabhAccount.getBalance());
|
2024-09-14 09:33:00 +05:30
|
|
|
saurabhAccount.computeInterest();
|
|
|
|
System.out.println("Saurabh's balance after interest: " + saurabhAccount.getBalance());
|
|
|
|
saurabhAccount.withdraw(2000);
|
|
|
|
System.out.println("Saurabh's balance after withdrawal: " + saurabhAccount.getBalance());
|
|
|
|
|
|
|
|
akhilAccount.deposit(2000);
|
2024-09-14 09:37:06 +05:30
|
|
|
System.out.println("Akhil's balance after deposit: " + akhilAccount.getBalance());
|
2024-09-14 09:33:00 +05:30
|
|
|
akhilAccount.withdraw(3000);
|
|
|
|
System.out.println("Akhil's balance after withdrawal: " + akhilAccount.getBalance());
|
|
|
|
akhilAccount.checkMinimumBalance();
|
|
|
|
System.out.println("Akhil's balance after checking minimum balance: " + akhilAccount.getBalance());
|
|
|
|
}
|
|
|
|
}
|