0% found this document useful (0 votes)
5 views5 pages

Java Bank Account Management System

The document contains Java code defining an abstract class for bank accounts and two subclasses: CreditAccount and SavingsAccount. It also includes a Bank class that manages a list of accounts and provides methods to display all accounts and only credit accounts. The Main class demonstrates adding accounts and displaying them using the Bank class methods.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Java Bank Account Management System

The document contains Java code defining an abstract class for bank accounts and two subclasses: CreditAccount and SavingsAccount. It also includes a Bank class that manages a list of accounts and provides methods to display all accounts and only credit accounts. The Main class demonstrates adding accounts and displaying them using the Bank class methods.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

ArrayList;

import [Link];

abstract class AbstractBankAccount {

protected String accountNumber;

protected double balance;

public AbstractBankAccount(String accountNumber, double initialBalance) {

[Link] = accountNumber;

[Link] = initialBalance;

public String getAccountNumber() {

return accountNumber;

public double getBalance() {

return balance;

public abstract void deposit(double amount);

public abstract void withdraw(double amount);

@Override

public String toString() {

return "Account Number: " + accountNumber + ", Balance: " + balance;

// [Link]
class CreditAccount extends AbstractBankAccount {

private double creditLimit;

public CreditAccount(String accountNumber, double initialBalance, double creditLimit) {

super(accountNumber, initialBalance);

[Link] = creditLimit;

@Override

public void deposit(double amount) {

if (amount > 0) {

balance += amount;

@Override

public void withdraw(double amount) {

if (amount > 0 && (balance + creditLimit) >= amount) {

balance -= amount;

@Override

public String toString() {

return [Link]() + ", Credit Limit: " + creditLimit;

// [Link]

class SavingsAccount extends AbstractBankAccount {


public SavingsAccount(String accountNumber, double initialBalance) {

super(accountNumber, initialBalance);

@Override

public void deposit(double amount) {

if (amount > 0) {

balance += amount;

@Override

public void withdraw(double amount) {

if (amount > 0 && amount <= balance) {

balance -= amount;

// [Link]

class Bank {

private List<AbstractBankAccount> accounts;

public Bank() {

accounts = new ArrayList<>();

public void addAccount(AbstractBankAccount account) {

[Link](account);

}
public void showAllAccounts() {

[Link]("All Accounts:");

for (AbstractBankAccount account : accounts) {

[Link](account);

public void showAllCreditAccounts() {

[Link]("All Credit Accounts:");

for (AbstractBankAccount account : accounts) {

if (account instanceof CreditAccount) {

[Link](account);

public class Main {

public static void main(String[] args) {

Bank bank = new Bank();

// Add different types of accounts

[Link](new CreditAccount("CA123", 1000.0, 5000.0));

[Link](new SavingsAccount("SA456", 2000.0));

[Link](new CreditAccount("CA789", 1500.0, 3000.0));

// Show all accounts

[Link]();

// Show only credit accounts

[Link]();
}

You might also like