Reading the specification I have decided that :
- This will be a multi-class program, as it needs to have the ability to store the data in memory.
- The main class will serve as a BankAccount, it will initialize with 0 balance and it will have public classes for the user to interact with like makeANewTransaction and printStetement.
- Another class will be named Transaction, every instance of this class will represent a different transaction made (like deposit or withdraw) to manage the data being recorded.
- The last class will be Statement, and it will be managing the output format and displaying the data to the user.
- The program will be written in JavaScript and will be tested with Jest.
Writing the class recipe
- Created User Stories based on specifications.
- Created a class diagram using the nouns and verbs extracted from the user stories.
- Created a sequence diagram to visualize how the classes will interact with each other.
- Created Examples as Unit Tests
- 3a. Create an example as a unit test
- 3b. encode the example
- 3c. implement the behavior (red-green-refactor)
- 3d. Go back to 3a until all criteria and cases are met
- Created Examples as integration Tests
- 4a. Create an example as an integration test
- 4b. encode the example
- 4c. implement the behavior (red-green-refactor)
- 4d. Go back to 4a until all criteria and cases are met
- Run the usage example given in the acceptance criteria to make sure that the specifications are met exactly.
The class BankAccount has 3 private fields: <#balance> , <#transactions> and <#statements> so every instance of the class starts with those 3 variables initialized to 0 and [], and they can only be accessed and changed within the class.
The class BankAccount has 2 private methods: <#balanceCalculation(amount)> and <#validateAmount(amount)> to help keep the quality of the code high, while ensuring that the sensitive features of the class are secure from misuse.
The class BankAccount has 3 public methods: printStatement(), deposit(amount) and withdraw(amount)
All the transactions made are instances of the class Transaction stored within the <#transactions> array with the date of the transaction that is calculated by obtaining the current date and formatting it as a string using the (English - United Kingdom) locale.
When the user wants to print their bank statement a new instance of the class Statement that includes the transactions stored in the <#transactions> array, at the time, <#transactions> array will be cleared, theinstance will stored in the <#statements> array and the function will return a string
If you haven't already have Node.js installed on your machine please follow the steps below.
First, you will need to install nvm - the Node Version Manager.
Running nvm install node and nvm use node will automatically install and use the latest stable version.
NVM is distributed using GitHub - you can find installation instructions for the latest
version here. You'll need to run
a command that looks like this:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Once that step is complete, you'll need to reload your ~/.zshrc file:
source ~/.zshrc
Now, you can install Node using nvm:
nvm install node
nvm use node
If the above works, you should see something like this in your terminal (exact versions
might be different for you!): Now using node v20.5.0 (npm v9.8.0) - if something went
wrong, have a look at the troubleshooting
section or reach out to someone
for help.
git clone https://github.com/LydiaNtafa/BankTechTest.git
cd
node
Welcome to Node.js v16.6.0.
Type ".help" for more information.
>
const BankAccount = require("./BankAccount");
const Account1 = new BankAccount();
const Account2 = new BankAccount();
for example:
Account2.deposit(100.6);
Account2.printStatement()
OR
Account1.deposit(1000);
Account1.deposit(2000);
Account1.withdraw(500);
Account1.printStatement()
Here you can find a Screenshot of Criteria Being Met
Make sure you are in the main project directory.
# Initialise the NPM project (this will create a file package.json)
npm init -y
# Add the jest package to our project (this will update package.json and package-lock.json)
npm add jest
# Also install jest "globally" (this is so we can run the `jest` command)
npm install -g jestjest
Here you can find a Screenshot of Test Coverage