Question
Using Java : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started