Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA: Since the job of this program is to store and audit transactions, let’s di

ID: 3744998 • Letter: J

Question

JAVA: Since the job of this program is to store and audit transactions, let’s discuss how those transactions will be submitted and stored within our program. Groups of transactions will be submitted together, and each of these groups will be represented by a perfectly sized array of primitive integers (perfect size vs oversize arrays). We’ll see later that the encoding of these integers may vary from one group of transactions to the next, and so keeping track of each group of transactions as distinct from the others will be important. The collection of these groups of transactions will be represented by an oversize array of transaction groups (or of perfect size integer arrays).

The first method that we will implement adds a perfectly sized array of transactions into an oversize array of perfect size integer arrays. The signature and behavior of this method must exactly match the following:

After implementing this method, you should create a file with an empty class definition named AuditableBankingTests.  

* Adds a transaction group to an array of transaction groups. If the alTransactions array is already full then this method will do nothing other than return allTransactionCount. 5*@param newTransactions is the new transaction group being added (perfect size) 6@param allTransactions is the collection that newTransactions is being added to Coversize) 7@param alLTransactionsCount is the number of transaction groups within allTransactions (before newTransactions is added 9@return the number of transaction groups within allTransactions after newTransactions is added. 10 */ 11 public static int submitTransactions(int newTransactions, int1 allTransactions, int allTransactionsCount) t 13 14 return -1; 153

Explanation / Answer

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks

// AuditableBankingTests.java

import java.util.Arrays;

public class AuditableBankingTests {

      /**

      * adds a transaction group to an array of transaction groups

      *

      * @param newTransactions

      *            - is the new transaction group to be added (perfect size)

      * @param allTransactions

      *            -is the collection that newtransaction is being added to

      * @param allTransactionsCount

      *            - count of transaction groups within allTransactions (before

      *            adding newtransactions )

      * @return count of transaction groups within allTransactions (after adding

      *         newtransactions )

      */

      public static int submitTransactions(int[] newTransactions,

                  int[][] allTransactions, int allTransactionsCount) {

            // checking if allTransactions is full or not

            if (allTransactionsCount < allTransactions.length) {

                  // not full, adding to the array

                  allTransactions[allTransactionsCount] = newTransactions;

                  // incrementing count of transaction groups

                  allTransactionsCount++;

            }

            // returning the new allTransactionsCount

            return allTransactionsCount;

      }

      public static void main(String[] args) {

            // code for testing the submitTransactions method

            // defining some perfect sized integer arrays

            int trans1[] = { 10, 20, 30, 40, 50 };

            int trans2[] = { 11, 22, 33, 44, 55 };

            int trans3[] = { 100, 200, 300, 400, 500 };

           

            // defining an over sized integer array

            int allTrans[][] = new int[4][];

            int count = 0;

            //adding one transaction

            System.out.println("Adding trans1");

            count = submitTransactions(trans1, allTrans, count);

            System.out

                        .println("Current number of transaction groups within allTransactions: "

                                    + count);

            //adding second and third transactions

            System.out.println("Adding trans2 and trans3");

            count = submitTransactions(trans2, allTrans, count);

            count = submitTransactions(trans3, allTrans, count);

            System.out

                        .println("Current number of transaction groups within allTransactions: "

                                    + count);

            //displaying the oversized transactions array

            System.out.println("Transactions: ");

            for (int i = 0; i < count; i++) {

                  System.out.println(Arrays.toString(allTrans[i]));

            }

      }

}

/*OUTPUT*/

Adding trans1

Current number of transaction groups within allTransactions: 1

Adding trans2 and trans3

Current number of transaction groups within allTransactions: 3

Transactions:

[10, 20, 30, 40, 50]

[11, 22, 33, 44, 55]

[100, 200, 300, 400, 500]