You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Require the BankAccount class with const BankAccount = require('./src/BankAccount');
Create a new bank account with const account = new BankAccount();
Deposit money with account.deposit(1000); (replace 1000 with the amount you want to deposit)
Withdraw money with account.withdraw(500); (replace 500 with the amount you want to withdraw)
To print your statement:
Require the Statement class with const Statement = require('./src/statement');
Create a statement with const statement = new Statement(account.transactions);
Print your statement with console.log(statement.format());
Screenshot of app in use:
To run the tests:
Run npm test to run the tests
Test coverage report
File
% Stmts
% Branch
% Funcs
% Lines
Uncovered Line #s
All files
100
100
100
100
bankAccount.js
100
100
100
100
statement.js
100
100
100
100
transaction.js
100
100
100
100
Test Suites: 4 passed, 4 total
Tests: 26 passed, 26 total
Snapshots: 0 total
Time: 0.294 s, estimated 1 s
Specification
Requirements
You should be able to interact with your code via a REPL like IRB or Node. (You don't need to implement a command line interface that takes input from STDIN.)
Data can be kept in memory (it doesn't need to be stored to a database or anything).
Acceptance criteria
Given a client makes a deposit of 1000 on 10-01-2023 And a deposit of 2000 on 13-01-2023 And a withdrawal of 500 on 14-01-2023 When she prints her bank statement Then she would see
The statement is printed in reverse chronological order
The date is formatted DD/MM/YYYY on the statement
The date is formatted DD-MM-YYYY in the specification
The amount is formatted to 2 decimal places on the statement
The amount is formatted to no decimal places in the specification
Each column is separated by 2 pipes (||)
The first line is a header
Shows a running balance
credit and debit are differentiated by || so debit has || on the left and credit has || on the right
Questions (Sent to client on 22/05/23 at 12:34pm - responses below):
Can the account balance go negative?
Worth taking into consideration as a edge case. For now, assume no.
Can there be multiple deposits/withdrawals on the same day? How should these be ordered?
Yes, same order as accepted criteria. (reverse chronological)
Is there a maximum number of transactions that can be shown on the statement?
No
What happens if the user tries to withdraw more money than they have in their account?
Edge case, assume no.
What happens if the user tries to withdraw or deposit 0 or a negative amount?
Edge case, assume no.
What happens if the user tries to deposit or withdraw a float? Should this be rounded to 2 decimal places only?
As per the acceptance criteria, assume no.
Should the code handle any specific errors or exceptions, such as invalid dates, strings or floats over or below 2 decimal places?
Yes, handle these errors.
Should the credit and debit column have a + or - symbol to differentiate between the two?
No as per acceptance criteria.
The inputs are deposit and withdrawal but no date. Should this be an input or defaulted to todays date?
Whichever would reduce the risk of human error. (So default to todays date and time for the transaction.)
User Stories:
As a user, I want to deposit money into my account.
As a user, I want to withdraw money from my account.
As a user, I want to see my account balance.
As a user, I want to print my account statement to view my account history.
As a user, I want to see the date of each transaction in my account history.
As a user, I want to see the amount of each transaction in my account history.
As a user, I want to see the balance after each transaction in my account history.
As a user, I want to see my transactions in reverse chronological order in my account history.
As a user, I want to view my transactions in a readable format in my account history.
Approach
Deposits:
Should accept a valid deposit amount (integer or float up to 2 decimal places). - DONE
Should update the balance with the deposit amount. - DONE
Should reject invalid deposit amounts (negative, non-numeric). - DONE
Should store the transaction with a auto generated timestamp. - DONE
Withdrawals:
Should accept a valid withdrawal amount (integer or float up to 2 decimal places). - DONE
Should update the balance by deducting the withdrawal amount. - DONE
Should reject invalid withdrawal amounts (negative, non-numeric, larger than balance). - DONE
Should store the transaction with a auto generated timestamp. - DONE
Account statement:
Should print all transactions in reverse chronological order. - DONE
Each transaction should include: date, credit or debit, balance after transaction. - DONE
The formatting should match the provided criteria. - DONE