Deposit

Report a typo

Write a program to calculate the deposit.

The input accepts 3 values in the following order: starting amount of money, interest rate, and the number of years during which the deposit is accrued.

The bank increases the deposit by the specified percentages every year. This can be described by the following formula:

finalAmount=startingAmount(1+yearlyPercent100)yearsfinalAmount=startingAmount \cdot \left(1 + \frac{yearlyPercent}{100}\right)^{years}

The program should convert the entered strings to BigDecimal and calculate how much money will be in the account after given years. The result should be rounded upwards, to positive infinity (CEILING mode), up to 2 (two) digits after the dot.

The program should output the following string: "Amount of money in the account: <>". Instead of <> must be the total amount of money.

It is guaranteed that all numbers are positive and the number of years is an integer.

Tip: Look at the example:

val number = BigDecimal("20")
val hundred = BigDecimal("100")
println(number/hundred) // 0

What happens here? Well, the scale of the number is 0 so the result has the scale 0 too. Possible solution:

val number = BigDecimal("20")
val hundred = BigDecimal("100")
println(number.setScale(2 + number.scale()) / hundred) // 0.20

Sample Input 1:

100000.2
20
1

Sample Output 1:

Amount of money in the account: 120000.24

Sample Input 2:

589456.67
15
5

Sample Output 2:

Amount of money in the account: 1185607.91
Write a program in Kotlin
import java.math.BigDecimal
import java.math.RoundingMode

fun main() {
// write your code here

}
___

Create a free account to access the full topic