subject

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 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?

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 20:40
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
question
Computers and Technology, 24.06.2019 09:00
Technician a says that a new replacement part is always good. technician b says that sometimes recent repair work will be the cause of a complaint. who is correct? a. both technicians a and b b. technician a c. technician b d. neither technician a nor b
Answers: 3
question
Computers and Technology, 24.06.2019 23:40
Which slide should you change so it reflects om all sides of your presentation
Answers: 1
question
Computers and Technology, 25.06.2019 01:30
Once a vulnerability has been identified by nessus, where would you check for more information regarding the identified vulnerability, exploits, and any risk mitigation solution?
Answers: 1
You know the right answer?
Objectives:
junit testing
collections: set
logic exception handling
gettin...
Questions
Questions on the website: 13722367