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

The interest paid on a savings account is compounded daily. This means that if y

ID: 3768003 • Letter: T

Question

The interest paid on a savings account is compounded daily. This means that if you start with startbal dollars in the bank, at the end of the first day you’ll have a balance of
startbal * (1 + rate/365)
dollars, where rate is the annual interest rate (0.10 if the annual rate is 10 percent). At the end of the second day, you’ll have
startbal * (1 + rate/365) * (1 + rate/365)
dollars, and at the end of n days you’ll have
startbal * (1 + rate/365)n
dollars. Write a program that processes a set of data records, each of which contains values for rate, startbal, and n and computes the final account balance.

Explanation / Answer

import java.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class FinalAccountBalance {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub

       double rate, startbal;
       int n;
       Scanner scanner = new Scanner(System.in);
       do {
           System.out.print("Enter the Start Balance:");
           startbal = scanner.nextDouble();

           System.out.print("Enter the Rate:");
           rate = scanner.nextDouble();

           System.out.print("Enter the no of days:");
           n = scanner.nextInt();

           double endBal = calculateBalance(rate, startbal, n);

           System.out.println("End Balance:" + endBal);
           System.out.print("Would you like to continue(y/n):");
           String ch = scanner.next();
           if (ch.equalsIgnoreCase("n")) {
               break;
           }

       } while (true);

   }

   /**
   * calculates final account balance
   *
   * @param rate
   * @param startbal
   * @param n
   * @return
   */
   static double calculateBalance(double rate, double startbal, int n) {
       double endBal = 0.0;
       endBal = startbal * (1 + rate / 365) * n;

       return endBal;
   }

}

OUTPUT:

Enter the Start Balance:5000
Enter the Rate:0.10
Enter the no of days:5
End Balance:25006.849315068488
Would you like to continue(y/n):y
Enter the Start Balance:15000
Enter the Rate:0.10
Enter the no of days:10
End Balance:150041.09589041094
Would you like to continue(y/n):n

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