r/JavaProgramming • • Oct 30 '25

Java OOP Banking System

Hi guys, I made this code as practice, I'm trying to improve but don't know where to start, I'm learning Java for almost 3 months now and I'm wondering how I'm doing, can anyone give some tips?

144 Upvotes

24 comments sorted by

View all comments

2

u/Lopsided-Stranger-81 Oct 31 '25

https://github.com/carlojaybacus14-cyber/Java-OOP-Banking-System.git
I made this repository in Github, I'm constantly changing the code

1

u/d-k-Brazz Oct 31 '25

2. Inheritance

This means you may build hierarchy of classes - higher and lower level
All lower level classes will inherit all public behavior of higher level classes

Example

abstract class Account {
  private String name;
  private String number;
  private BigDecimal amount;
  
  // withdraw amount from the account
  public abstract void debit(BigDecimal sum);
  // add amount to the account
  public abstract void credit(BigDecimal sum);
}  

class PassiveAccount extends Account {
  // forbids crediting below 0
}

class ActiveAccount extends Account {
  // forbids debiting above 0
}

class SavingsAccount extends PassiveAccount {
  // customer's savings
  // may have attributes like interest rate, 
  // or limitations like possibility of partial
  // withdrawal before the end of savings contract
}

class CheckingAccount extends PassiveAccount {
  // allows any transfers within the available amount
}

class BanksCashAccount extends ActiveAccount {
  // cash funds in possession of the bank
  // transferring from this account to another 
  // means someone has brought some cash to the bank
  // negative value reflects amount of cash money in the bank
}

class LoanAccount extends ActiveAccount {
  // may have attributes like interest rate, 
  // credit limit etc.
}

This will allow you to build common logic for all account:

public void transfer(Account accFrom, Account accTo) {
  // the logic inside does not care of kinds of accounts
  // each account limitations and constraints are encapsulated 
  // inside the according Account ancestor class
  // 
  // this is method of a Bank class and from bank's perspective
  // each transfer should be consistent
  // this means that if you successfully debited accFrom, 
  // but crediting accTo has failed, you have return money to accFrom back
}

Using this common method you can deposit cash money to an account, transfer money to a counterparty, withdraw a part of a load etc.