Question: 2. Write a unit test to test the following class. import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen

2. Write a unit test to test the following class.

import java.util.*; public class BankAccount { private String customerName;

private double balance;

private boolean frozen = false;

private BankAccount() { }

public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; }

public String getCustomerName() { return customerName; }

public double getBalance() { return balance; }

public void setDebit(double amount) throws Exception { if (frozen) { throw new IllegalArgumentException("Cannot divide by 0!"); }

if (amount > balance) { throw new Exception("amount"); }

if (amount < 0) { throw new Exception("amount"); }

balance += amount; // intentionally incorrect code }

public void setCredit(double amount) throws Exception { if (frozen) { throw new Exception("Account frozen"); }

if (amount < 0) { throw new Exception("amount"); }

balance += amount; }

private void FreezeAccount() { frozen = true; }

private void UnfreezeAccount() { frozen = false; } }

The main method

import java.util.*; public class BankaccountTest {

public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BankAccount ba = new BankAccount("Mr. Bryan Walton", 3.5);

ba.setCredit(5.00); ba.setDebit(2.0); System.out.println("Current balance is " + ba.getBalance());

}

}

Test only the debit method in the BankAccount.

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!