Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP PLEASE! Objectives: JUnit Testing Collections: Set Logic exception handling Getting Started To begin this lab, create a new Java project named abc123-lab7 ,

JAVA HELP PLEASE!

Objectives:

JUnit Testing

Collections: Set

Logic exception handling

Getting Started

To begin this lab, create a new Java project named abc123-lab7, and create the following packages and classes:

bank.Account.java

bank.Bank.java

This lab does not deal with synchronized or multithreading. Correct solutions to this lab may not be thread-safe.

Banks & Accounts

Bank.java will define functionality for a bank. Banks must have a name and a set of accounts. Use a java.util.Set implementation of your choosing for this data structure, and the Account.java implementation for the accounts stored. Bank.java must have a single constructor to properly initialize banks. In addition, there should be an overloaded method called addAccount which can add Account objects to the bank given either a name for the account, or both a name for the account and a starting balance. This method will create an Account object and add it to the set stored in the Bank object, nothing will be returned. Creating a new object would be as follows: Bank bank = new Bank("Gringotts");

Account.java will define functionality for an account. Accounts must have a name associated with them, an account number, and a balance. As described above, an Account object can be defined using either all three of these (name, number, and balance) or only with the name and number. (This indicates the constructor must be overloaded - one for each of these cases.) If a starting balance is not provided, it will be assumed to be 0. There should be getters and setters for all of these three variables. Account.java must have two additional methods: deposit and withdraw. deposit will be an object method that takes in an amount of money and adds the amount to the balance of an account. Deposits should inherently only the positive values. This method will return the new balance of the account. withdraw will be an object method that takes in an amount of money and reduces the balance by that amount. Withdrawls should inherently only be positive values. Withdrawls larger than the current balance should not be permitted. This method will return the new balance of the account. Creating a new object would be as follows: Account account1 = new Account("Amy Smith", 2202); or Account account2 = new Account("Bob Smith", 1584, 100.0);

JUnit Testing

Create a JUnit 4 Test Case, called AccountTest.java. This class will test only the functionality in the Account class, defined above. Implement the following methods:

setUp() - Method runs before each test is run.

testInit() - Test the constructors.

testValidDeposit() - Test depositing a valid amount (i.e. positive amount) into the account.

testInvalidDeposit() - Test depositing an invalid amount (i.e. negative amount) into the account.

testValidWithdrawl() - Test withdrawing a valid amount (i.e. positive amount) from the account.

testInvalidWithdrawl() - Test withdrawing an invalid amount (i.e. negative amount) from the account.

testOverdraft() - Test withdrawing more than the balance from the account.

No test methods should be created for the getters or setters in the Account class. Each method should have the appropriate JUnit annotation. Overdrafts should not be permitted, instead a message must be presented to the user. For each test listed, consider the preconditions and postconditions of the method in testing. Consider any input (parameters), logical requirements (described in the class descriptions above), and outputs (returned values). What could go wrong when the method is called? Equally important, what could be wrong after the method is called? In the process of implementing these tests, you should run them and verify they are passing. If a test does not pass, first assess the test (is it set up correctly?), then verify your implementation meets the requirements (see Account.java above). A completed submission for this lab will correctly assess all test cases, and running AccountTest.java will result in a pass (green bar in the JUnit view).

Note that your submitted Eclipse project must include the dependecy for JUnit 4. To ensure this, export your code from Eclipse to an archive file, as in the lab instructions!

Unsure about a test or implementation? Imagine you are writing code for your bank. How do you want your money to be handled? If you were to try to deposit or withdraw an invalid amount of money, would you want your account balances to be affected? Would you want to be warned of the error?

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 Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

What is the method of least squares?

Answered: 1 week ago

Question

Describe who performs human resource management activities.

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago