Tags | skill/combined_concept_projects |
Hard Prerequisites | |
IMPORTANT: Please review these prerequisites, they include important information that will help you with this content. | |
|
You have just been hired by a fin-tech startup. Your mission is to build a bank. It’s going to be a cute little bank, real banks are waaaay more complicated.
Your directory structure should look like this:
├── banking
│ └── bank_account.py
├── setup.py
├── requirements.txt
├── .gitignore
└── tests
└── ???
Please use pytest
to test your work.
Your directory structure should look like this:
├── spec
| ├── support
| | └── jasmine.json
| └── ???
├── src
| └── bank_account.js
└── package.json
Please test your work using jasmine.
Please make use of Gradle from the command line to set up your project. You can learn more about Gradle here:
[TODO] TOPIC: African Coding Network SyllabusYour project name should be banking
.
Make sure that all of the classes you define are within the banking
package. Do this by including a package declaration at the top of each of your java files.
Your directory structure should look like this:
├── app
| ├── build.gradle
| └── src
| ├── main
| | └── java
| | └── banking
| | └── BankAccount.java <-------- names are important
| |
| └──test
| └── java
| └── banking
| └── ???.java <-------- names are important
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
Let’s say you have a bank account with an interest rate of 12% (that’s really high, lucky you) and you have $1000 in your bank account. How much interest would you earn in one month?
12% of $1000 = (1000/100) x 12 = 120. So in a year you would earn $120. So in one month you would earn $10.
So if you just left your bank account alone for a while then here is how the balance would look over time:
Notice that we aren’t just adding $10 every month. The interest is being calculated based on what is currently in the account at any point in time. This is called compounding interest. If you don’t know about compounding interest it would be good to learn a bit about financial literacy.
Create a class called BankAccount
A Bank Account has the following properties:
balance
: This is the amount of money stored in the bank account.interest rate
: This shows how much interest gets earned per year. An interest rate of 3.5
means you would get 3.5% interest per yearAdd the following functions:
deposit
- This function should take in a single positive number. That number should get added to tha BankAccount’s balance.withdraw
- This function should take in a single positive number. That number should be subtracted from the BankAccount’s balancecompound_interest
- this will calculate the interest for the month and add it to the balance.Example usage:
// JavaScript:
const account = new BankAccount({ interestRate: 12 }); // when a bank account is constructed, you must set the interest rate. Take note of the curly brackets
console.log(account.balance); // this will print 0.00
account.deposit({ amount: 1500 });
console.log(account.balance); // this will print 1500.00
account.withdraw({ amount: 500 });
console.log(account.balance); // this will print 1000.00
account.compoundInterest();
console.log(account.balance); // this will print 1010.00
# Python:
account = BankAccount(
interest_rate=12
) # when a bank account is constructed, you must set the interest rate
print(account.balance) # this will print 0.00
account.deposit(amount=1500)
print(account.balance) # this will print 1500.00
account.withdraw(amount=500)
print(account.balance) # this will print 1000.00
account.compound_interest()
print(account.balance) # this will print 1010.00
// Java:
BankAccount account = new BankAccount(12); // when a bank account is constructed, you must set the interest rate
System.out.println(account.balance); // this will print 0.00
account.deposit(1500);
System.out.println(account.balance) ; // this will print 1500.00
account.withdraw(500);
System.out.println(account.balance); // this will print 1000.00
account.compoundInterest();
System.out.println(account.balance); // this will print 1010.00
Computers are good at a lot of things. But things can get a little bit weird when it comes to floating point numbers.
Whenever you are dealing with financial applications you need to make sure you are using high accuracy numbers. Different languages do things differently.
Please make use of Decimal. The documentation explains the problem.
This Stackoverflow question explains the problem.
Please make use of Decimal.js.
This Stackoverflow question explains the problem.
You will need to make use of the BigDecimal class for your numbers.
This is a bank so you have to take things very seriously. It’s critical that you test all your work, test coverage should be 100%.
Also, please make use of assertions within your code to make sure that errors are raised if you try to: