Savings Account Balance Write a program that calculates the balance of a savings
ID: 3904005 • Letter: S
Question
Savings Account Balance
Write a program that calculates the balance of a savings account at the end of a
period of time. It should ask the user for the annual interest rate, the starting
balance, and the number of months that have passed since the account was
established. A loop should then iterate once for every month, performing the
following:
1) Ask the user for the amount deposited into the account during the month.
This amount should be added to the balance.
2) Ask the user for the amount withdrawn from the account during the
month. This amount should be subtracted from the balance.
3) Calculate the monthly interest. The monthly interest rate is the annual
interest rate divided by 12. Multiply the monthly interest rate by the
balance and add the result to the balance.
After the last iteration, the program should display the ending balance, the
total amount of deposits, the total amount of withdrawals, and the total
interest earned.
PROGRAM AND DOCUMENTATION REQUIREMENTS:
1) The program must be modular. You should have, at minimum, separate
modules for each of the following: main, user input, monthly calculations, and
output. You may include more if you would like.
2) Include a program analysis worksheet.
3) The program should utilize user friendly prompts and messaging for all
interaction with the user.
4) Include a hierarchy chart.
5) Include internal program documentation (comments).
6) Plan the program logic using both pseudocode and flowchart methods.
Explanation / Answer
import java.util.*;
import java.io.*;
class SavingsAccountBalance
{
Scanner sc=new Scanner(System.in);
double annualRate,Balance,totalDeposit=0.0,totalWithdrawl=0.0,totalIntrest=0.0;
static int monthsPassed=0;
void input()
{
System.out.println("Enter annual intrest rate, starting Balance and No of months passed since account creation");
annualRate=sc.nextDouble();
Balance=sc.nextDouble();
monthsPassed=sc.nextInt();
}
void monthlyCalculations(int i)
{
System.out.println("Enter the money deposited in the month "+(i+1));
double monDeposit=sc.nextDouble();
System.out.println("Enter the money withdrawl in the month "+(i+1));
double monWithdrawl=sc.nextDouble();
totalDeposit=totalDeposit+monDeposit;
totalWithdrawl=totalWithdrawl+monWithdrawl;
Balance=Balance+monDeposit-monWithdrawl;
double monIntrest=(annualRate/1200)*Balance;
totalIntrest=totalIntrest+monIntrest;
Balance=Balance+monIntrest;
}
void output()
{
System.out.println("Ending Balance:"+Balance);
System.out.println("Total Deposist:"+totalDeposit);
System.out.println("Total Withdrawl:"+totalWithdrawl);
System.out.println("Total Intrest Earned:"+totalIntrest);
}
public static void main(String[] args)
{
SavingsAcountBalance ob=new SavingsAcountBalance();
ob.input();
for(int i=0;i<monthsPassed;i++)
ob.monthlyCalculations(i);
ob.output();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.