Program for Bank
// Base Account class
class Account {
public double balance;
public double interest;
}
// SavingsAccount class extends Account
class SavingsAccount extends Account {
// Default constructor
public SavingsAccount() {
balance = 0;
interest = 0;
}
// Parameterized constructor
public SavingsAccount(double initialBalance, double initialInterest) {
balance = initialBalance;
interest = initialInterest;
}
// Method to deposit amount
public void deposit(double amount) {
balance += amount;
}
// Method to withdraw amount
public void withdraw(double amount) {
balance -= amount;
}
// Method to add interest
public void addInterest() {
balance += balance * interest;
}
// Method to get current balance
public double getBalance() {
return balance;
}
}
// Tester class with main method
public class Tester {
public static void main(String[] args) {
SavingsAccount a1 = new SavingsAccount(1000, 0.10); // Create account with 1000 balance and 10% interest
a1.withdraw(250); // Withdraw 250
a1.deposit(400); // Deposit 400
a1.addInterest(); // Add interest
System.out.println("Final Balance: " + a1.getBalance()); // Display final balance
}
}