Outstanding Balance on the Credit Card
2. Katas
Problem:
Write a program that considers the Outstanding Balance on the Credit Card if you pay only the Minimum Payment for a whole year.
For this, three variables are given to enter the function:
- outStandingBalance - outstanding balance on credit card.
- yearlyPercentRate - yearly percent rate.
- monthlyPercentRate - monthly percent rate.
Note: if you want to know how to calculate the outstanding balance after one month, See the section below. Example.
Task:
Write a function that returns such a string: "Remaining Outstanding Balance: b", where b is the outstanding balance (rounded to the second decimal point) that the function returned.
!Also, Prints these lines while the function is running:
Month 1 Outstanding Balance: b | Minimum payment this month: m ... Month 1 Outstanding Balance: b | Minimum payment this month: m when b - Outstanding Balance, а m - Minimum payment this month.
Example:
To calculate the outstanding balance after one month, one must adhere to such an algorithm:
-
Consider the minimum payment that we can make in a month:
minPay = outStandingBalance * monthlyPercentRate
-
Consider the balance, after the minimum payment:
balanceAfterMinPay = outStandingBalance - minPay
-
Consider the percentage that we have to pay for using the card per month:
Percent = (yearlyPercentRate / 12.0) * balanceAfterMinPay
-
Consider the outstanding balance at the end of the month:
outStandingBalance = balanceAfterMinPay + Percent
Do not forget that we counted only for one month.
Data to verify:
creditCardOutStanding - Function name
- creditCardOutStanding(3329,0.2,0.03) --> "Remaining Outstanding Balance: 2816.55"
- creditCardOutStanding(341,0.12,0.053) --> "Remaining Outstanding Balance: 207.63"
- creditCardOutStanding(168,0.15,0.06) --> "Remaining Outstanding Balance: 92.81"
Where "-->" means after starting the program
What's next ?
The program does not come out or works not exactly,go to the solution folder and look at the explanation for solving the problem, this will help you.
If you have everything turned out, you can go to the solution package and compare your solution with the one that's there.
If your decision does not coincide with my decision, then I'm very happy for you. Please share it with me, I will be very grateful to you and then I will add it to the solution folder. How to add your solution, see here