Problem statement
In this challenge, we will implement methods in the parent class and its corresponding child class.
The initializers for both classes have been defined for you.
Task 1
In the Account class, implement the getBalance() method that returns balance.
Task 2
In the Account class, implement the deposit(amount) method that adds amount to the balance. It does not return anything.
Sample input
balance = 2000
deposit(500)
getbalance()
Sample output
2500
Task 3
In the Account class, implement the withdrawal(amount) method that subtracts the amount from the balance. It does not return anything.
Sample input
balance = 2000
withdrawal(500)
getbalance()
Sample output
1500
Task 4
In the SavingsAccount class, implement an interestAmount() method that returns the interest amount of the current balance. Below is the formula for calculating the interest amount:
Sample input
balance = 2000
interestRate = 5
interestAmount()
Sample output
100
The following figure shows what the result should logically look like:
Based and Derived Classes Structure
Coding exercise
Design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so initially try to solve it on your own. If you get stuck, you can always refer to the solution provided in the next lesson.
Good luck!