Question

Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12- this interest should be added to savingsBalance. Provide a static method setInterestRate that sets the annualInterestRate to a new value. There should also be a method setSavingsBalance to set the initial savings balance for a new saver or you can do it through a constructor.

Write a program to test class SavingsAccount. Instantiate two SavingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest for 12 months and print the new balances for both savers. Next, set the annualInterestRate to 5%, calculate the next month's interest and print the new balances for both savers.

Put the code to test the class in the main method of the Savings Account Class. The output of your program should look like the following:

х Untitled - Notepad File Edit Format View Help savings Account Balances Saver1 2006. 67 2013.36 2020.07 2026. 80 2033. 56 20

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.


class SavingsAccount {

//variable to store annual interest rate
static private double annualInterestRate;
private double savingBalance;

//constructor method
public SavingsAccount()
{
this.savingBalance=0;
}
//Constructor method
public SavingsAccount(double savingBalance)
{
this.savingBalance=savingBalance;
}
//Get saving balance
public double getSavingBalance()
{
return this.savingBalance;
}
public double[] getMonthsSavingBalance(int total_months)
{
double[] monthlyI_month=new double[total_months];
double monthlyI;
for(int i=0;i<total_months;i++)
{
monthlyI= (double)(this.savingBalance*annualInterestRate/12);
this.savingBalance+=monthlyI;
monthlyI_month[i]=this.savingBalance;
}
return monthlyI_month;
}
// Modify interest rate by setting annual interest rate to a new value
public static void modifyInterestRate(double newInterestRate)
{
annualInterestRate=newInterestRate;
}
//Method to calculate monthly interest
public void calculateMonthlyInterest()
{
double monthlyI;
monthlyI= (double)(this.savingBalance*annualInterestRate/12);
this.savingBalance+=monthlyI;
}
}
public class TestSavingAccount {

public TestSavingAccount() {
}
public static void main(String[] args)
{
SavingsAccount saver1,saver2;
saver1 = new SavingsAccount (2000.0);
saver2 = new SavingsAccount (3000.0);
int total = 0;
SavingsAccount.modifyInterestRate (0.04);
int total_month=12; // Show Complete Balance Till 12 Month
double[] balance_month=saver1.getMonthsSavingBalance(total_month); // I have added This Function that will calculate till which month you want
System.out.println("Savings Account Balance");
System.out.printf("Month\tSaver1\tSaver2\n");
double[] balance_month1=saver2.getMonthsSavingBalance(12);
for(int i=0;i<total_month;i++)
{
System.out.printf("%d\t%.2f\t%.2f\n",(i+1),balance_month[i],balance_month1[i]);
}


SavingsAccount.modifyInterestRate(0.05);
balance_month=saver1.getMonthsSavingBalance(12);   
balance_month1=saver2.getMonthsSavingBalance(12); // I have added This Function that will calculate till which month you want

for(int i=0;i<total_month;i++)
{
System.out.printf("%d\t%.2f\t%.2f\n",(i+13),balance_month[i],balance_month1[i]);
}


  
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • Application should be in C# programming language Create a class called SavingsAccount.  ...

    Application should be in C# programming language Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the...

  • Define a class SavingsAccount with following characteristics. Use a static variable annualInterestRate of type float to...

    Define a class SavingsAccount with following characteristics. Use a static variable annualInterestRate of type float to store the annual interest rate for all account holders. Private data member savingsBalance of type float indicating the amount the saver currently has on deposit. Method calculateMonthlyInterest to calculate the monthly interest as (savingsBalance * annualInterestRate / 12). After calculation, the interest should be added to savingsBalance. Static method modifyInterestRate to set annualInterestRate. Parameterized constructor with savingsBalance as an argument to set the value...

  • C# How to Program: 10.5 Savings account class

    Create the class savings account. Use the static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the classcontains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate themonthly interest by multiplying the savingsBalance by annualInterestRate divided by 12, this interest should be added to savingsBlance, Provide static methodModifyInterestRate to set the annualInterestRate to a new value. Write an application to test class SavingsAccount....

  • Using C++ Please make sure you comment each section of the program so I can better...

    Using C++ Please make sure you comment each section of the program so I can better understand it. Thank you! Assignment Content You are now working for a bank, and one of your first projects consists of developing an application to manage savings accounts. Create a C++ program that does the following: Creates a SavingsAccount class Uses a static data member, annualInterestRate, to store the annual interest rate for each of the savers Ensures each member of the class contains...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’...

    Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this back can deposit (i.e. credit) money into their accounts and withdraw (i.e. debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction. Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit...

  • •create a new savings account object (for choice 2). •ask the user to enter an initial...

    •create a new savings account object (for choice 2). •ask the user to enter an initial balance which should be greater than 50. If the entered amount is less than 50, the program will ask the user to enter another amount. This continues until an amount greater than 50 is entered. •Set the balance of the savings account object by calling the setBalance() method. •Ask the user to deposit an amount. Deposit that amount and display the balance of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT