JAVA HELP Create a class SavingsAccount Use a static class
[JAVA HELP]
---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class contains a private instance variable savingsBalance indicating the amount save currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provde a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a driver program to test the class SavingsAccount. Instantiate two different savingsAccount objects, saver1 and saver2 with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4% then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 5% and calculate the next months interest and print the new balances or each of the savers.
---Write another class SpecialSavings that extends SavingsAccount to pay interest of 10% on accounts that have balances that exceed 10K. Also provide methods to deposit and take money out of savings account. Write a driver program to test the class SpecialSavings. Instantiate two different SavingAccount objects saver1 and saver2 with a balance of 2000.00 and 3000.00 Make a few deposits and withdrawls and show balance.
Include a scanner class to enter different deposit and withdraw amounts and display current interest rate and balance.
NEED total of four classes Please. (SavingAccount) - (SpecialSaving) - (SavingaccountTest) - (SpecialSavingTest)
Solution
import java.util.*;
class SavingAccount
{
static double annualInterestRate;
double savingsBalance;
//Constructor for SavingAccount
SavingAccount(double sb, double ai)
{
savingsBalance = sb;
annualInterestRate = ai;
}
//Calculate Monthly Interest
public void calculateMonthlyInterest()
{
savingsBalance = savingsBalance + (savingsBalance * 1 * annualInterestRate)/12;
System.out.println(\" New Balance = \" + savingsBalance);
}
//Modifies Interest Rate
public static void modifyInterestRate(double d)
{
annualInterestRate = d;
}
}
//Class Special Savings derived from SavingAccount
class SpecialSavings extends SavingAccount
{
//Constructor for SpecialSavings
SpecialSavings(double d, double dd)
{
super(d, dd); //Calls base class constructor (i.e., SavingAccount)
}
//Method for deposit
public static void deposit(SavingAccount sa, double d)
{
sa.savingsBalance = sa.savingsBalance + d;
System.out.println(\"\ New Balance = \" + sa.savingsBalance);
}
//Method for Withdrawl
public static void withdrawls(SavingAccount sa, double w)
{
sa.savingsBalance = sa.savingsBalance - w;
System.out.println(\"\ New Balance = \" + sa.savingsBalance);
}
//Special interest
public static void newPer(SavingAccount sa)
{
if(sa.savingsBalance > 10000)
sa.savingsBalance = sa.savingsBalance * .10;
System.out.println(\"\ New Balance After Special Interest: \" + sa.savingsBalance);
}
}
//Test class for Special Savings
class SpecialSavingTest
{
Scanner sc = new Scanner(System.in); //Scanner class object created
//Constructor for SpecialSavingTest class
SpecialSavingTest()
{
double de = 0.0, wi = 0.0;
//Creates the First instance saver1 of Saving Account class
SavingAccount saver1 = new SavingAccount(2000.00, 4);
//Creates the Second instance saver2 of Saving Account class
SavingAccount saver2 = new SavingAccount(3000.00, 4);
System.out.println(\"\ First Saver: \");
saver1.calculateMonthlyInterest();
System.out.println(\"\ Second Saver: \");
saver2.calculateMonthlyInterest();
//After modifying the Interest Rate
SavingAccount.modifyInterestRate(5);
System.out.println(\"\ First Saver: \");
saver1.calculateMonthlyInterest();
System.out.println(\"\ Second Saver: \");
saver2.calculateMonthlyInterest();
System.out.println(\"\ Enter the deposit Amount \");
de = sc.nextDouble();
SpecialSavings.deposit(saver1, de);
System.out.println(\"\ Enter the withdrawl Amount \");
wi = sc.nextDouble();
SpecialSavings.withdrawls(saver1, wi);
//Special Interest
SpecialSavings.newPer(saver1);
SpecialSavings.newPer(saver2);
}
}
//Test class SavingaccountTest for Saving Account
public class SavingaccountTest
{
public static void main(String ss[])
{
SpecialSavingTest sst = new SpecialSavingTest();
}
}
Output:
First Saver:
New Balance = 2666.6666666666665
Second Saver:
New Balance = 4000.0
First Saver:
New Balance = 3777.7777777777774
Second Saver:
New Balance = 5666.666666666667
Enter the deposit Amount
100
New Balance = 3877.7777777777774
Enter the withdrawl Amount
10
New Balance = 3867.7777777777774
New Balance After Special Interest: 3867.7777777777774
New Balance After Special Interest: 5666.666666666667
![[JAVA HELP] ---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class cont [JAVA HELP] ---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class cont](/WebImages/19/java-help-create-a-class-savingsaccount-use-a-static-class-1041829-1761541280-0.webp)
![[JAVA HELP] ---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class cont [JAVA HELP] ---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class cont](/WebImages/19/java-help-create-a-class-savingsaccount-use-a-static-class-1041829-1761541280-1.webp)
![[JAVA HELP] ---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class cont [JAVA HELP] ---Create a class SavingsAccount . Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class cont](/WebImages/19/java-help-create-a-class-savingsaccount-use-a-static-class-1041829-1761541280-2.webp)