Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program named InterestCalculator.java that calculates the value of

ID: 3870475 • Letter: W

Question

Write a Java program named InterestCalculator.java that calculates the value of a bank account based on starting principle, interest rate and time. Prompt the user for the Number of quarters to display (int) that is greater than zero and less or equal to 10. Starting balance (double) that is greater than zero. Interest rate (double) that is greater than zero and less than or equal to 20%. Display the information the user entered and ask if it is correct. If so continue, if not ask for all the information again (loop and half example in Addition Iteration examples). Calculate the ending balance for each quarter and display the results in a table similar to below, the formula for quarterly balance is b + (b * IR/100 * .25) where b is starting balance and IR is interest rate.

Explanation / Answer

InterestCalculator.java

import java.util.Scanner;

public class InterestCalculator {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the Number of quarters to display: ");

int n = scan.nextInt();

while(n < 0 || n > 10){

System.out.println("Invalid Input. Enter the Number of quarters to display: ");

n = scan.nextInt();

}

System.out.println("Enter the Starting balance: ");

double balance = scan.nextDouble();

while(balance<0) {

System.out.println("Invalid input. Enter the Starting balance:");

balance = scan.nextDouble();

}

System.out.println("Enter the Interest rate: ");

double interest = scan.nextDouble();

while(interest<0 || interest>20) {

System.out.println("Invalid input. Enter the Interest rate: ");

interest = scan.nextDouble();

}

for(int i=0;i<n;i++){

balance = balance + (balance * interest)/100 * 0.25;

System.out.println("Quarter "+(i+1)+" Balance: "+balance);

}

}

}

Output:

Enter the Number of quarters to display:
3
Enter the Starting balance:
10000
Enter the Interest rate:
5
Quarter 1 Balance: 10125.0
Quarter 2 Balance: 10251.5625
Quarter 3 Balance: 10379.70703125

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote