Asks you to: 1.) Write a Savings Account class that stores a savings account'sannual interest rate and balance The class constructor should acceptthe amount of the savings account's starting...




Asks you to:

1.) Write a Savings Account class that stores a savings account'sannual interest rate and balance The class constructor should acceptthe amount of the savings account's starting balance. The classshould also have methods for subtracting the amount of a withdrawl,adding the amount of a deposite, and adding the amount of monthlyinterest to the balance. The monthly interest rate is the annualinterest rate divided by 12. To add the monthly interest to the balance,multiply the monthly interest rate by the balance and add the result tothe balance.

2.) Test the class (create a driver class) in a program that calculatesthe balance of a savings account at the end of a period of time. Itshould 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 class method to calculate monthly interest.





I have created the SavingsAccount.java and the SavingsAccountTest.java (driver)and the MAIN PROBLEM: WHEN I RUN IT (both compile fine) THE BALANCE IS NOTBEING UPDATED BY THE DEPOSITS, WITHDRAWS, OR INTEREST - SO WHEN I DISPLAY THE"ENDING BALANCE" IT DISPLAYS AS "0.00". The deposit and withdraw for each monthand then the totalDeposits and totalWithdrawn seems to be calculating correctlytoo. I am not sure about the interest as this part really confuses me.Please look at my program and notice the variable (I do have a problem managingmodule level variables & fear I create to many variables than needed at times )- please don't refer to them as different names - and keep in mind that this ischapter 5 & we have not incorporated overloading methods, static fields ormethods or anything beyond that yet.

_______________________________________________________________________________



SavingsAccount.java:





/**

* SavingsAccount Class

* This class sets up the SavingsAccount class

*/



import java.util.Scanner; // Needed for Scanner

import java.io.*; // Needed for File and IOException



public class SavingsAccount

{

private double balance; // Account Balance

private double withdraw; // Account Withdrawals

private double deposit; // Account Deposits

private double interestRate; // Account annual InterestRate

private double interest; // Account monthly Interest

private double totalDeposits;

private double totalWithdrawn;



/**

* The constructor initializes the balance and interestRate fields

* with the values passed to startBalance and intRate. The interest

* field is assigned 0.0.

*/



public SavingsAccount (double startBalance,

double intRate)

{

balance = startBalance;

interestRate = intRate;

interest = 0.00;

}



// The getBalance method returns the value in the balance field.



public double getBalance()

{

return balance;

}



// The setDeposit method accepts the argument that is stored in

// the deposit field.



public void getDeposit(double depAmount)

{

deposit = depAmount;

}



// The addDeposit method add the deposit to the balance.



public void addDeposit()

{

balance = (balance + deposit);

}



// The setWithdraw method accepts the argument that is stored in the

// withdraw field.



public void setWithdraw(double withAmount)

{

withdraw = withAmount;

}



//The subtractWithdraw method subtracts the withdraw from the

// balance.



public void subtractWithdraw()

{

balance = (balance - withdraw);

}



// The getInterestRate method returns the value in the interestRate

// field.



public double getInterestRate()

{

return interestRate;

}



// The calculateInterest method calculates the monthly interest and adds

// it to the account balance.



public void calculateInterest()

{

interest = (interestRate / 12);

interest = (balance * interest);

}



// The addInterest method adds the moInterest to the



public void addInterest()

{

balance = (balance + interest);

}



// The getInterest method returns the value in the interest field.



public double getInterest()

{

return interest;

}



// The addTotalDeposits method adds all deposits for the months the account

// has been active.



public void addTotalDeposits()

{

totalDeposits = totalDeposits + deposit;

}



// The getTotalDeposits method returns the value in totalDeposits.

public double getTotalDeposits()

{

return totalDeposits;

}



// The addTotalWithrawn method adds all deposits for the months the account

// has been active.



public void addTotalWithdrawn()

{

totalWithdrawn = totalWithdrawn + withdraw;

}



// The getTotalWithdrawn method returns the value in totalWithdrawn.



public double getTotalWithdrawn()

{

return totalWithdrawn;

}

}



_______________________________________________________________________________



SavingsAccountTest.java (driver class)





/**

* SavingsAccountTest class

* This class sets up the driver class for the SavingsAccount.

*/



import java.util.Scanner; // Needed for Scanner

import java.io.*; // Needed for File and IOException

import java.text.DecimalFormat; // Needed to format the decimals in variable values.



public class SavingsAccountTest

{

public static void main(String[] args) throws IOException

{

SavingsAccount account;

double bal = 0.00;

double intRate = 0.00;

int months = 0;

double depAmount;

double withAmount;

double totalDeposits = 0.00;

double totalWithdrawn = 0.00;



// Create a Scanner object for keyboard input.

Scanner keyboard = new Scanner(System.in);



// Create a SavingsAccount object.

account = new SavingsAccount(bal, intRate);



// Create a Decimal Format object to set $ amouts display.

DecimalFormat dollar = new DecimalFormat("##,##0.00");



// Get the starting balance.

System.out.println("Enter the savings account's starting balance: ");

bal = keyboard.nextDouble();



// Get the annual interest rate.

System.out.println("Enter the savings account's annual interest rate: ");

intRate = keyboard.nextDouble();

account.getInterestRate();



// Get the number of month the savings account has been open.

System.out.println("How many months have passed since the account "

+ "was opened? :");

months = keyboard.nextInt();



// Process the information for the months.

for (int month = 1; month <=>

{

// Get the account's balance.

bal = account.getBalance();



// Get the amount of the deposit.

System.out.println("Enter the amount deposited during month "

+ month + ": ");

depAmount = keyboard.nextDouble();

account.addDeposit();



// Running total for deposits.

totalDeposits = (totalDeposits + depAmount);



// Get the amount of the withdraw.

System.out.println("Enter the amount withdrawn during month "

+ month + ": ");

withAmount = keyboard.nextDouble();

account.subtractWithdraw();



// Running total for withdraw.

totalWithdrawn = (totalWithdrawn + withAmount);



// Calculate the interest for the month.

account.calculateInterest();

account.addInterest();

}



// Display the total deposited.

account.addTotalDeposits();

account.getTotalDeposits();

System.out.println("Total deposited: $" + dollar.format(totalDeposits));





// Display the total withdrawn.

account.addTotalWithdrawn();

account.getTotalWithdrawn();

System.out.println("Total withdrawn: $" + dollar.format(totalWithdrawn));



// Display the ending balance.

System.out.println("Ending balance: $" + dollar.format(account.getBalance()));

}

}



____________________________________________________________________________________


May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here