Answer to Question #318088 in Java | JSP | JSF for Jay

Question #318088

1)     Write a program that accepts the amount of money deposited in a bank account, the annual interest rate and the target amount (The amount of money the account holder wants to have in the account after a period of time) and then calculates the number of years it will take for the money to accumulate to the targeted amount. NB: 1) The interest being earned is Compound Interest. 2) Don’t use the formula for calculating compound interest.

For example if the money deposited is 10000 and the target amount is 20000 and the account earns an interest rate (compound) of 10% pa, then the output should be: -

It will take 8 years for your money to reach your target.

By the end of this period, the amount in your account will be 21435.89    


1
Expert's answer
2022-03-25T12:10:37-0400
import java.text.DecimalFormat;
import java.util.Scanner;

public class Test {
    public static int accumulation(double amountOfMoney, double interest, double targetAmount){
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        double currentTargetAmount = amountOfMoney;
        int years = 0;
        double multiplier = interest / 100;
        while (targetAmount > currentTargetAmount){
            currentTargetAmount += currentTargetAmount * multiplier;
            years++;
        }
        System.out.println("By the end of this period, the amount in your account will be " + decimalFormat.format(currentTargetAmount));
        return years;
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        double AmountOfMoney;
        double Interest;
        double TargetAmount;
        System.out.print("Enter amount of money: ");
        AmountOfMoney = scanner.nextDouble();
        System.out.print("Enter interest: ");
        Interest = scanner.nextDouble();
        System.out.println("Enter target amount: ");
        TargetAmount = scanner.nextDouble();
        System.out.print("It will take " + accumulation(AmountOfMoney, Interest, TargetAmount) + " years for your money to reach your target.");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS