Skip to content

Synthird/object-oriented-bank-account

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object Oriented Bank Account

An OOP class library for simulating bank accounts.

It is not meant for full-blown banking systems in everyday life.

Documentation is also available.

Sample code
import makingtransactions.NegativeBalanceException;
import makingtransactions.Transaction;
import makingtransactions.bankaccounts.JointAccount;
import makingtransactions.bankaccounts.SingleAccount;
import userservice.User;

public class TestZone {
	public static void main(String[] args) throws NegativeBalanceException {
		User charlie = new User("Charlie", 15, 25);
		User john = new User("John", 15, 21);

		SingleAccount singleAccount = new SingleAccount(45, charlie, "Single", "USD", 152, 23, 12);
		JointAccount jointAccount = new JointAccount(charlie, "Joint", "USD", 02, 01, 20);

		System.out.println("--- Swapping single account owners ---");

		System.out.println("Charlie's accounts: " + charlie.getBankAccounts());
		System.out.println("John's accounts: " + john.getBankAccounts());

		singleAccount.setUserHolder(john);

		System.out.println("\nSwapped holder to john:\n");
		System.out.println("User holder: " + singleAccount.getUserHolder());

		System.out.println("Charlie's accounts: " + charlie.getBankAccounts());
		System.out.println("John's accounts: " + john.getBankAccounts());

		System.out.println("--- Adding and removing joint account users ---");

		System.out.println(jointAccount.getUsers());

		jointAccount.addUser(john);
		System.out.println(jointAccount.getUsers());

		jointAccount.addUser(john);
		System.out.println(jointAccount.getUsers());

		jointAccount.removeUser(charlie);
		System.out.println(jointAccount.getUsers());

		jointAccount.removeUser(john);
		System.out.println(jointAccount.getUsers());

		System.out.println("--- TRANSACTIONS ---");

		Transaction transaction = new Transaction("Groceries", 0, 0, 12);

		System.out.println("Single account before: " + singleAccount.getBalance());

		singleAccount.addTransaction(transaction);

		System.out.println("Single account now: " + singleAccount.getBalance());
		System.out.println("Single account transactions: " + singleAccount.getTransactions());
	}
}

Installation

The library is contained in a jar file in the releases page.

Note: The process of inserting the jar file into your project depends on your IDE and build tools.

Visual Studio Code Java project (No build tools)

Download the jar file and place it into the lib folder, which is located at the root of the project.

Jar file in the root folder of a non-build tools Java project

If there is not a lib folder at the root folder, create it.

License

This repository contains the MIT license. You must give credit if you are going to use its source code or the class library.

Packages

No packages published

Languages