Question

Write a unit test to test the following class. Using Java : //Test only the debit...


Write a unit test to test the following class.

Using Java :

//Test only the debit method in the BankAccount.

:

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());

}

}


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Write a unit test to test the following class. Using Java : //Test only the debit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • How would I alter this code to have the output to show the exceptions for not...

    How would I alter this code to have the output to show the exceptions for not just the negative starting balance and negative interest rate but a negative deposit as well? Here is the class code for BankAccount: /** * This class simulates a bank account. */ public class BankAccount { private double balance; // Account balance private double interestRate; // Interest rate private double interest; // Interest earned /** * The constructor initializes the balance * and interestRate fields...

  • Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount....

    Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount. Implement four methods: • public void deposit(double amount, String account) • public void withdraw(double amount, String account) • public void transfer(double amount, String account) • public double getBalance(String account) Here the account string is "S" or "C". For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is...

  • WHERE in this code should you put the main method so that the code will compile...

    WHERE in this code should you put the main method so that the code will compile WITHOUT changing anything else in the code? Simply adding the main method only? public class Account { private String name; private double balance;    public Account(String name, double balance) { this.name = name; if (balance > 0.0) this.balance = balance; } public void deposit(double depositAmount) { if (depositAmount > 0.0) balance += depositAmount; }    public double getBalance() { return balance; } public String...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • Hello everybody. Below I have attached a code and we are supposed to add comments explaining...

    Hello everybody. Below I have attached a code and we are supposed to add comments explaining what each line of code does. For each method add a precise description of its purpose, input and output.  Explain the purpose of each member variable. . Some help would be greaty appreciated. (I have finished the code below with typing as my screen wasnt big enough to fit the whole code image) } public void withdrawal (double amount) { balance -=amount; }...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT