Question: For programming 5.12 Account class (the actual code is below): { Account acct1 = new Account(Ted Murphy, 72354, 25.59); Account acct2 = new Account(Angelica Adams,

For programming 5.12 Account class (the actual code is below):

{

Account acct1 = new Account("Ted Murphy", 72354, 25.59);

Account acct2 = new Account("Angelica Adams", 69713, 500.00);

Account acct3 = new Account("Edward Demsey", 93757, 769.32);

acct1.deposit(44.10); // return value ignored

double adamsBalance = acct2.deposit(75.25);

System.out.println("Adams balance after deposit: " + adamsBalance);

System.out.println("Adams balance after withdrawal: " + acct2.withdraw(480, 1.50));

acct3.withdraw(-100.00, 1.50); // invalid transaction

acct1.addInterest();

acct2.addInterest();

acct3.addInterest();

System.out.println();

System.out.println(acct1);

System.out.println(acct2);

System.out.println(acct3);

}

}

Account.Java

import java.text.NumberFormat;

public class Account

{

private final double RATE = 0.035; // interest rate of 3.5%

private long acctNumber;

private double balance;

private String name;

// -----------------------------------------------------------------

// Sets up the account by defining its owner, account number,

// and initial balance.

// -----------------------------------------------------------------

public Account(String owner, long account, double initial)

{

name = owner;

acctNumber = account;

balance = initial;

}

// -----------------------------------------------------------------

// Deposits the specified amount into the account and returns

// the new balance. The balance is not modified if the deposit

// amount is invalid.

// -----------------------------------------------------------------

public double deposit(double amount)

{

if (amount > 0)

balance = balance + amount;

return balance;

}

// -----------------------------------------------------------------

// Withdraws the specified amount and fee from this account and

// returns the new balance. The balance is not modified if the

// withdraw amount is invalid or the balance is insufficient.

// -----------------------------------------------------------------

public double withdraw(double amount, double fee)

{

if (amount + fee > 0 && amount + fee < balance)

balance = balance - amount - fee;

return balance;

}

// -----------------------------------------------------------------

// Adds interest to the account and returns the new balance.

// -----------------------------------------------------------------

public double addInterest()

{

balance += (balance * RATE);

return balance;

}

// -----------------------------------------------------------------

// Returns the current balance of this account.

// -----------------------------------------------------------------

public double getBalance()

{

return balance;

}

// -----------------------------------------------------------------

// Returns a one-line description of this account as a string.

// -----------------------------------------------------------------

public String toString()

{

NumberFormat fmt = NumberFormat.getCurrencyInstance();

return (acctNumber + "\t" + name + "\t" + fmt.format(balance));

}

}

The question is add a new constructor Account(String owner, long account). Also add a new instance method public double compoundInterestAfter(int yrs) which returns the balance after accumulating interest for yrs years at the given interest rate. But: do NOT change the current balance field when this method is called; just calculate and return what the new balance would be.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!