I need help with this project. The program needs to be in Java and please follow
ID: 3908399 • 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 accept 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
/**
Analysis :-
The problem takes input of initial amount(int), yearly interest(float) and number of months it has been deposited.
For each month it asks for amount deposited(int) and amount withdrawn(int).
For each month it calculates the new balance and adds the interest.
It should be noted that interest of newly deposted money is also added.
Then it displays current balance, amount deposited, amount withdrawn and interest earned.
Design :-
class SavingsAccount is constructed by taking the initial balance.
Methods to set interest, add money, withdraw money, add monthly interest is given;
Data part of the class is having variables for balance, total amount withdrawn, total amount deposited, total interest earned.
Driver class asks for initial amount, interest rate(in percentage) and months it has been deposited.
Then for each month it asks for amount withdrawn and deposited.
It then invokes the methods for depositing, withdrawing and adding interest.
It finally shows the balance, amount deposited, amount withdrawn and interest earned.
Code :- Kindly compile in a file named driver.java
Do not use any other name
Else change the class named driver
*/
import java.util.Scanner;
class SavingsAccount{
private int balance;
private float interest = 0;
private int BalanceWithdrawn = 0;
private int BalanceDeposited = 0;
private int InterestEarned = 0;
SavingsAccount(int InitialBalance){
balance = InitialBalance;
};
public void SetInterest(float AnnualInterest){
interest = AnnualInterest;
}
public int GetBalance(){
return balance;
}
public int AddBalance(int amount){
balance = balance + amount;
BalanceDeposited = BalanceDeposited + amount;
return BalanceDeposited;
}
public int WithdrawAmount(int amount){
balance = balance - amount;
BalanceWithdrawn = BalanceWithdrawn + amount;
return BalanceWithdrawn;
}
public int MonthlyInterest(){
float MonthlyInterest;
MonthlyInterest = interest/12;
MonthlyInterest = (balance*MonthlyInterest)/100;
balance = balance + (int)MonthlyInterest;
InterestEarned = InterestEarned + (int)MonthlyInterest;
return InterestEarned;
}
}
public class driver{
public static void main(String[] args){
System.out.println("Kindly enter the amount of initial balance :");
Scanner in = new Scanner(System.in);
int balance = in.nextInt();
SavingsAccount savingsaccount = new SavingsAccount(balance);
System.out.println("Kindly enter the Interest rate :");
float interest = in.nextFloat();
savingsaccount.SetInterest(interest);
System.out.println("Kindly enter the number of months it has been established :");
int number = in.nextInt();
int BalanceWithdrawn = 0;
int BalanceDeposited = 0;
int InterestEarned = 0;
for(int i = 0; i<number; i++){
System.out.println("Kindly enter the amount deposited in month " + (i + 1) + ":");
BalanceDeposited = savingsaccount.AddBalance(in.nextInt());
System.out.println("Kindly enter the amount withdrawn in month " + (i + 1) + ":");
BalanceWithdrawn = savingsaccount.WithdrawAmount(in.nextInt());
InterestEarned = savingsaccount.MonthlyInterest();
}
System.out.println("Current balance is : " + savingsaccount.GetBalance() + "only");
System.out.println("Total amount deposited is : " + BalanceDeposited + " only");
System.out.println("Total amount withdrawn is : " + BalanceWithdrawn + " only");
System.out.println("Total interest earned is : " + InterestEarned + " only");
}
}