Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task #8 (1 point): Writing an additional class (in a separate file) that tests each of the methods that you are assigned to write. Please

Task #8 (1 point): Writing an additional class (in a separate file) that tests each of the methods that you are assigned to write. Please call this program TestBankAccount, TestCustomer, or TestEmployee (whichever is appropriate for your assigned class). This class should contain a main method that tests your class.

Task #9 (6 points):

Your test class should test the other class that you made by instantiating at least 2 objects...

Make 1 object using the default constructor to make sure it compiles correctly (1 point)

Make the other object using the parameterized constructor to make sure it compiles correctly (1 point)

Test each object to see if the id or account number is properly set. (1 point)

Test 1 object to see if it correctly uses the setter to change the value. (1 point)

Test 1 object to see if it doesn't update the value if a invalid value is used. (1 point)

Test the toString method for at least 1 object. (1 point)

Label each of the tests with a comment that includes the test number.

/** * BankAccount is a class that represents an account at a bank. It maintains a balance, allows accessing of the balance, and allows updating of the balance. Each account must have a unique account number. * * @author [Your Name] * @version [Date] */ public class BankAccount { // attributes private int accountNumber; private double balance; private static int nextAccount = 1000;

/** * Advance the account number to the next number. */ private static void advanceNextAccount() { nextAccount++; }

/** * Default Constructor: Sets the balance to 0 and assigns the account number using the shared attribute. */ public BankAccount() { balance = 0; accountNumber = nextAccount; advanceNextAccount(); }

/** * Constructor: the caller of the method will provide the starting balance. The starting balance may only be non-negative, and it should be between 0 and positive $10,000. The account number should be set in the same way as the other constructor. * * @param startBalance the starting balance * @throws IllegalArgumentException if startBalance is negative or greater than 10000 */ public BankAccount(double startBalance) throws IllegalArgumentException { if (startBalance < 0 || startBalance > 10000) { throw new IllegalArgumentException("Balance must be between 0 and 10000"); } balance = startBalance; accountNumber = nextAccount; advanceNextAccount(); }

/** * Get the account number. * * @return the account number */ public int getAccountNumber() { return accountNumber; }

/** * Get the balance. * * @return the balance */ public double getBalance() { return balance; }

/** * Set the balance of the class to the given balance. The new balance should be a non-negative value that is less than $100,000,000. Accounts whose values become too high are also not allowed. * * @param newBalance the new balance * @throws IllegalArgumentException if newBalance is negative or greater than 100000000 */ public void setBalance(double newBalance) throws IllegalArgumentException { if (newBalance < 0 || newBalance > 100000000) { throw new IllegalArgumentException("Balance must be between 0 and 100000000"); } balance = newBalance; }

/** * Return a string representation of the account. * * @return a string in the form of ACCT# [accountNumber]: $[balance] */ public String toString() { return "ACCT# " + accountNumber + ": $" + balance; } }

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions