Personal Project of EBU6304 Software Engineering (2022/23)
This is a Java project that implements a basic bank account management system, allowing users to create accounts, deposit and withdraw money, and manage their accounts.
- Multiple account types, including savings, CurrentAccount, and JuniorAccount
- Withdraw policy for CurrentAccount and JuniorAccount
- Ability to suspend and close accounts
- Java unit tests for each account type and the Bank class
- Data persistence using JSON (v1)
- Ability to change the type of account (v2)
- Fast lookup enabled by HashMap (v3)
- IntelliJ IDEA (recommended)
- Java Development Kit (JDK) 8 or later
- Maven 3.2 or later
-
Clone the repository:
git clone https://github.com/Wiederholung/Simple-Banking-System.git
-
Navigate to the directory where you downloaded the repository:
cd Simple-Banking-System
Optional: open the project in IDEA
-
Compile:
mvn compile
-
Run unit tests:
mvn test
You can create different types of accounts with varying properties and features. A sample code shows how to create an account and perform some actions on it:
package com.metattri.se;
import java.io.IOException;
public class Sample {
public static void main(String[] args) {
Bank bank;
try {
bank = new Bank();
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("new account number: " + bank.openAccount(new CurrentAccount("your name")));
bank.deposit("test", 500.0);
bank.withdraw("test", 1000.0);
System.out.println(bank.checkBalance("test"));
bank.suspendAccount("test", true);
assert !bank.deposit("test", 1000.0);
bank.suspendAccount("test", false);
String newAccNo = null;
try {
newAccNo = bank.changeAccountType("test", "CurrentAccount");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
System.out.println("new account number: " + newAccNo);
bank.closeAccount(newAccNo);
bank.printAccounts();
}
}
Note
-
See more usage in the JUnit tests and design details in the UML diagram.
-
The account number is a UUID, which is a random string. You can look up the account number via:
bank.printAccounts();
String accNo = bank.openAccount(new BankAccount("your name"));
- accounts.json
-
The database file accounts.json is stored in the directory
src/main/resources
, which is the default directory for resources in Maven. You can change the directory in the Bank.java file. -
After running the JUnit tests or Sample.java, you can check the database file to see the changes.
-
Remember to rollback the changes in the accounts.json if you want to run the tests again.