Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public

Using Java :

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

l Discuss several concerns about appraisal feedback interviews.

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago