Question: Binary Amount Transactions: When the first number (at index zero) within a transaction group array is zero, the rest of the numbers in that array
Binary Amount Transactions: When the first number (at index zero) within a transaction group array is zero, the rest of the numbers in that array represent transactions encoded as Binary Amount Transactions. Each binary amount transaction is either a zero or a one. Ones represent deposits of $1, and zeros represent withdraws of $1. Any other numbers found in such transaction arrays represent errors, but we will not test how your code responds to such errors, so you can ignore them.
Integer Amount Transactions: When the first number (at index zero) within a transaction group array is one, the rest of the numbers in that array represent transactions encoded as Integer Amount Transactions. Integer amount transactions can be either positive or negative integers. Positive integers represent deposits of the specified integer amount, and negative integers represent withdraws of the specified amount. Any zeros found within such transactions represent errors, but we will not test how your code responds to such errors, so you can ignore them.
Quick Withdraw Transactions: When the first number (at index zero) within a transaction group is two, the rest of the numbers in that array represent transactions encoded as Quick Withdraw Transactions. The non-negative integer numbers within quick withdraw transaction arrays represent the numbers of withdraws, rather than the amounts of withdraws (as was the case with the previous encoding). The amounts for quick withdraws are fixed at $20, $40, $80, and $100. And the number of withdraws of each amount is stored at indexes one, two, three, and four respectively. This means that the size of every quick withdraw array should be five. Arrays of other sizes, and negative withdraw amounts both represent errors, but we will not test how your code responds to such errors, so you can ignore them.
For the purpose of this program, the user will enter each group of transactions as a string of integers separated by spaces, which conforms to one of these three encoding standards. For example, they might enter this string containing a binary amount transaction:
0 1 0 0 1 1 1 0 1
Define a new method called processCommand that takes such a string as command/input, and correctly adds a new transaction group to the provided set of transactions groups. When the first character within a command does not correspond to a valid transaction encoding or the allTransactions array starts out full, this method should not make any changes to allTransactions. Note in the required method signature below, that this method returns an int (as is required to keep track of the potentially growing size of our oversize array):
| 1 2 3 4 | public static int processCommand(String command, int[][] allTransactions, int allTransactionsCount) { // TODO: Implement this method return -1; } |
The following methods from the Java8 API may be helpful in implementing this processCommand method:
Integer.parseInt(string) returns an integer encoding of the number represented by the string input.
string.trim() returns a new copy of the string this method is called on, but without any leading or trailing whitespace.
string.split( ) breaks the string this method is called on into parts around each space, and returns all of those parts as a single array of strings.
Since it is currently difficult to tell whether this method is working, we are going to write a test method within AuditableBankingTests to help us verify this. Add a method to this class with the following signature:
| 1 2 3 4 | public static boolean testProcessCommand() { // TODO: Implement this method return false; } |
This test method should test BankingTests.processCommand by passing in some hard-coded arguments (a command like 0 0 1 1 0 1 1 into an oversize array containing two prior transaction groups) and checking whether the return value and contents of allTransactions match the specified behavior (like allTransactions[2][2] == 1). Try checking for at least two very specific defects within in this test, and keep this test code as simple as possible to avoid the likelihood of confounding bugs within your tests. This method should print out feedback about any defects that it finds. In addition to this feedback for human eyes, this method should return false when any defects are found and true when none are found. Create a main method within your BankingTests class to run this test (and additional tests that you add in the future).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
