I need help with this project. The program needs to be in Java and please follow
ID: 3910583 • Letter: I
Question
I need help with this project. The program needs to be in Java and please follow the description below. thank
SavingsAccount class
Design a SavingsAccount class that stores a savings account’s annual interest rate and balance. The class constructor should ac`cept the amount of the savings account’s starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly interest to the balance. The monthly interest rate is the annual interest rate divided by twelve. To add the monthly interest to the balance, multiply the monthly interest rate by the balance, and add the result to the balance. Test the class in 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:
a. Ask the user for the amount deposited into the account during the month. Use the class method to add this amount to the account balance.
b. Ask the user for the amount withdrawn from the account during the month. Use the class method to subtract this amount from the account balance.
c. Use the class method to calculate the monthly interest. 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.
Analysis:
(Describe the problem including input and output in your own words.)
Design:
(Describe the major steps for solving the problem.)
Coding: (Copy and Paste Source Code here
Explanation / Answer
import java.io.*;
import java.util.*;
class SavingsAccount {
private double balance;
private double annualIntrestRate;
public SavingsAccount(double bal, double r){
balance = bal;
annualIntrestRate = r;
}
double getBalance(){
return balance;
}
void deposit(double a){
balance = balance + a;
}
void withdraw(double a){
if (a >= balance)
balance = balance - a;
}
double calculateMonthlyIntrest(){
return (annualIntrestRate/1200)*balance;
}
void updateAccountMonthly(){
balance = balance + calculateMonthlyIntrest();
}
}
public class Demo202{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the starting balance:");
double bal = Double.parseDouble(sc.nextLine());
System.out.println("Enter the annual intrest rate:");
double r = Double.parseDouble(sc.nextLine());
System.out.println("Enter number of months passed:");
int n = Integer.parseInt(sc.nextLine());
SavingsAccount s = new SavingsAccount(bal,r);
for (int i = 0; i<n; i++){
s.updateAccountMonthly();
}
double tdeposit = 0;
double twithdraw = 0;
double intr = 0;
for (int i = 0; i<12; i++){
System.out.println("Enter deposit for month:" + (i+1) + ":");
double amt = Double.parseDouble(sc.nextLine());
s.deposit(amt);
tdeposit = tdeposit + amt;
System.out.println("Enter withdrawl for month:" + (i+1) + ":");
amt = Double.parseDouble(sc.nextLine());
twithdraw = twithdraw + amt;
s.withdraw(amt);
intr = intr + s.calculateMonthlyIntrest();
s.updateAccountMonthly();
}
System.out.printf("Total Deposit: %.2f " , tdeposit);
System.out.printf("Total Withdrawls: %.2f " , twithdraw);
System.out.printf("Total Intrest: %.2f " , intr);
System.out.printf("Balance: %.2f " , s.getBalance());
}
}
/*
Input: Starting Balance, annual intrest rate, number of months passed,deposit input for each month, withdrawl input for each month
Processing:
1.Creation of account with starting balance and annual intrest rate
2.Update the account for the number of months passed
3.Update the account for each month withdrawl and deposit
4.Update the total deposit and total withdrawl with each month deposit and withdrawl
5.Calculate intrest for each month.Update the total intrest earned
6.Update the balance with monthly intrest rate
7.Didplay results
Output:
Total Balance, Total intrest earned, total withdrawls, total deposits
*/