Computers and Technology

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?

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:00, alyssashae1818
Which parts of a presentation should be the most general? a. introduction and conclusion b. introduction and outline c. outline and conclusion d. outline and body
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, DSUDLER5555
Write a program that prints the day number of the year, given the date in the form month-day-year. for example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. the program should check for a leap year. a year is a leap year if it is divisible by 4, but not divisible by 100. for example, 1992 and 2008 are divisible by 4, but not by 100. a year that is divisible by 100 is a leap year if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400. however, 1800 is not a leap year because 1800 is not divisible by 400.
Answers: 3
image
Computers and Technology, 24.06.2019 20:00, diangeloortiz
Which element will you include to present numerical on a slide? a: graph b: text c: flowchart d: shapes
Answers: 1
image
Computers and Technology, 25.06.2019 08:00, yungkxng57
Is a major factor in the widespread use of global information systems
Answers: 1
Do you know the correct answer?
Objectives:
junit testing
collections: set
logic exception handling
gettin...

Questions in other subjects: