Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I will give 1050 Karma points for this question. I will post the same question 3

ID: 3632267 • Letter: I

Question

I will give 1050 Karma points for this question. I will post the same question 3 times so you can submit the same answer 3 times for 1050 karma points

JUnit is a flexible framework for writing and running unit tests in Java. Now, given the following code,

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. Returns the
// new balance.
//-----------------------------------------------------------------
public double deposit (double amount)
{
balance = balance + amount;
return balance;
}
//-----------------------------------------------------------------
// Withdraws the specified amount from the account and applies
// the fee. Returns the new balance.
//-----------------------------------------------------------------
public double withdraw (double amount, double fee)
{
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 the account.
//-----------------------------------------------------------------
public double getBalance ()
{
return balance;
}
//-----------------------------------------------------------------
// Returns a one-line description of the account as a string.
//-----------------------------------------------------------------
public String toString ()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
return (acctNumber + " " + name + " " + fmt.format(balance));
}
}

Write a JUnit test class (named AccountTest.java) to test the Account class by doing
the following (1.5 points):
a. Create four accounts (hints: use setup):
• Account1: "Ted Murphy", 72354, 102.56
• Account2: "Jane Smith", 69713, 40.00
• Account3: "Edward Demsey", 93757, 759.32
• Account4 is an alias of Account1
b. Write a test method to test that Account1 and Account4 are aliases (hints: use
assertEquals).
c. Write a test method to test the deposit() method. Put $100 on Account1 and test if
the balance of Account1 is same as what you expect.
d. Write a test method to test the withdraw() method. Withdraw $10 with $2 fee
from Account2 and test if the balance of Account2 is same as what you expect.
e. Write a test method to test the addInterest() method. Get the interest on Account3,
and test if the interest is same as what you expect.
f. Write a test method to test the toString() method. Call toString on Account2, and
test if the result is same as what you expect.
g. Release the object references for the account object (hints: use tearDown).
Include execution traces without any failure.
Any UML modeling tool can be used.

Explanation / Answer

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. Returns the // new balance. //----------------------------------------------------------------- public double deposit (double amount) { balance = balance + amount; return balance; } //----------------------------------------------------------------- // Withdraws the specified amount from the account and applies // the fee. Returns the new balance. //----------------------------------------------------------------- public double withdraw (double amount, double fee) { 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 the account. //----------------------------------------------------------------- public double getBalance () { return balance; } //----------------------------------------------------------------- // Returns a one-line description of the account as a string. //----------------------------------------------------------------- public String toString () { NumberFormat fmt = NumberFormat.getCurrencyInstance(); return (acctNumber + " " + name + " " + fmt.format(balance)); } }