The file must be called (driver program) SavingsAccount.java (handles interest a
ID: 440952 • Letter: T
Question
The file must be called (driver program) SavingsAccount.java (handles interest and balance calculations)Example: KenDeweyProg4.java (driver program) SavingsAccount.java
Ensure you include ALL files required to make your program compile and run. I would like to see your .java files only.
Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter. 4
Overall Requirements
Write a program that establishes two savings accounts with saver1 having account number 10002 with an initial balance of $2,000, and saver2 having account 10003 with an initial balance of $3,000. Set a common rate of interest at 5% per year. At the end of each month, update the balance by adding one month
Explanation / Answer
This is the exact answer for ur question..
SavingsAccount Class
public class SavingsAccount {
private double annualInterestRate;
private int ACCOUNT_NUMBER;
private double balance;
public SavingsAccount(int aCCOUNT_NUMBER, double balance) {
super();
ACCOUNT_NUMBER = aCCOUNT_NUMBER;
this.balance = balance;
}
public SavingsAccount(double annualInterestRate, int aCCOUNT_NUMBER,
double balance) {
super();
this.annualInterestRate = annualInterestRate;
this.ACCOUNT_NUMBER = aCCOUNT_NUMBER;
this.balance = balance;
}
public SavingsAccount() {
super();
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public int getACCOUNT_NUMBER() {
return ACCOUNT_NUMBER;
}
public void setACCOUNT_NUMBER(int aCCOUNT_NUMBER) {
ACCOUNT_NUMBER = aCCOUNT_NUMBER;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double addMonthlyInterest()
{
double intrestBalance=balance * annualInterestRate / 12 ;
return intrestBalance;
}
}
YourNameProg4 Class
public class YourNameProg4 {
public static void main(String []args)
{
//instantiating saver1
SavingsAccount saver1=new SavingsAccount(10002,2000.00);
saver1.setAnnualInterestRate(0.05); //setting intrestrate for saver1
//instantiating saver2
SavingsAccount saver2=new SavingsAccount(10003,3000.00);
saver2.setAnnualInterestRate(0.05);//setting intrest rate for saver2
System.out.println("Monthly balances for one year with 0.05 annual interest:");
System.out.println("Month Account #Balance Account # Balance");
System.out.println("0 "+saver1.getACCOUNT_NUMBER()+" #"+saver1.getBalance()+" "+saver2.getACCOUNT_NUMBER()+" #"+saver2.getBalance());
for(int i=0;i<12;i++)
{
double newSaver1Balance=saver1.getBalance() +saver1.addMonthlyInterest();
saver1.setBalance(newSaver1Balance);
double newSaver2Balance=saver2.getBalance() + saver2.addMonthlyInterest();
saver2.setBalance(newSaver2Balance);
System.out.println((i+1) +" "+ saver1.getACCOUNT_NUMBER() +" #"+ newSaver1Balance +" "+ saver2.getACCOUNT_NUMBER() +" #"+newSaver2Balance );
}
System.out.println("Final balance of both accounts combined:"+ (saver1.getBalance() + saver2.getBalance()));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.