Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: 3. AUDITING TRANSACTIONS Next, well implement a method to calculate and return the total account balance based on a collection of provided transaction groups.

JAVA: 3. AUDITING TRANSACTIONS

Next, well implement a method to calculate and return the total account balance based on a collection of provided transaction groups. Here is the required signature for this method (to be implemented within AuditableBanking.java), along with the signature of a corresponding test method (to be implemented within AuditableBankingTests.java).

1

2

3

4

public static int calculateCurrentBalance(int[][] allTransactions, int allTransactionsCount) {

// TODO: Implement this method

return -1;

}

1

2

3

4

public static boolean testCalculateCurrentBalance() {

// TODO: Implement this method

return false;

}

Another form of auditing that we would like to perform on collections of transaction groups is to count the number of overdrafts. An overdraft is when a withdraw is made that results in a negative balance. To detect overdrafts, youll need to process collections of transaction groups in order of increasing indexes starting at zero. Within each group of transactions, you should processes transactions in order of increasing indexes too. Here is the signature of the method that you must implement, along with some test code to add to your AuditableBankingTests class. These tests should help you verify your own understanding of the required methods behavior, and should also help you begin to test your implementation of it.

1

2

3

4

public static int calculateNumberOfOverdrafts(int[][] allTransactions, int allTransactionsCount) {

// TODO: Implement this method

return -1;

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

public static boolean testCalculateNumberOfOverdrafts() {

boolean foundProblem = false;

int[][] transactions = new int[][] {

{1,10,-20,+30,-20,-20}, // +2 overdrafts (ending balance: -20)

{0,1,1,1,0,0,1,1,1,1}, // +2 overdrafts (ending balance: -15)

{1,115}, // +0 overdrafts (ending balance: +100)

{2,3,1,0,1}, // +1 overdrafts (ending balance: -100)

};

// test with a single transaction of the Integer Amount encoding

int transactionCount = 1;

int overdrafts = AuditableBanking.calculateNumberOfOverdrafts(transactions,transactionCount);

if(overdrafts != 2) {

System.out.println("FAILURE: calculateNumberOfOverdrafts did not return 2 when transactionCount = 1, and transactions contained: "+Arrays.deepToString(transactions));

foundProblem = true;

} else

System.out.println("PASSED TEST 1/2 of TestCalculateNumberOfOverdrafts!!!");

// test with four transactions: including one of each encoding

transactionCount = 4;

overdrafts = AuditableBanking.calculateNumberOfOverdrafts(transactions,transactionCount);

if(overdrafts != 5) {

System.out.println("FAILURE: calculateNumberOfOverdrafts did not return 5 when transactionCount = 4, and transactions contained: "+Arrays.deepToString(transactions));

foundProblem = true;

} else

System.out.println("PASSED TESTS 2/2 of TestCalculateNumberOfOverdrafts!!!");

return !foundProblem;

}

After you get these two methods working revisit your definition of the processCommand method. Update this method to calculate and print out the balance when the first non-white-space character within the command string is a B (upper or lower case), and to calculate and print out the number of overdrafts when the first non-white-space character within the command string is an O (upper or lower case). The following methods from the Java8 API may be helpful in updating the processCommand method in this way:

string.charAt(index) returns the character at the specified zero-based index from within this string.

string.toUpperCase() returns a new copy of the string this method is called on, but with an upper case version of each alphabetic character.

4. THE DRIVER APPLICATION

The last step of this assignment is to implement a nice text-based interface to access and drive the program. Organize this functionality into whatever custom static methods you see fit, but ensure that running the main method within your AuditableBanking class results in an interaction logs comparable to the sample shown below. All of your variables should be local to some static method (no class or instance fields are allowed), unless they are constants marked with the keyword final. Pay close attention to the details within the example log below, to ensure that your programs welcome message, thank you message, command prompts, current balance, and overdraft numbers are all printed in the same manner. You do not need to worry about erroneous input from the user, because all of our grading tests will focus on properly encoded commands, as described within this specification. The user should be able to submit at least 100 transaction groups. Note that the users input below is shown in red, and that the rest of the text below was printed out by the program.

========== Welcome to the Auditable Banking App ========== COMMAND MENU: Submit a Transaction (enter sequence of integers separated by spaces) Show Current [B]alance Show Number of [O]verdrafts [Q]uit Program ENTER COMMAND: 0 1 1 0 0 0 1 1 COMMAND MENU: Submit a Transaction (enter sequence of integers separated by spaces) Show Current [B]alance Show Number of [O]verdrafts [Q]uit Program ENTER COMMAND: 1 -10 +100 COMMAND MENU: Submit a Transaction (enter sequence of integers separated by spaces) Show Current [B]alance Show Number of [O]verdrafts [Q]uit Program ENTER COMMAND: 2 2 1 0 0 COMMAND MENU: Submit a Transaction (enter sequence of integers separated by spaces) Show Current [B]alance Show Number of [O]verdrafts [Q]uit Program ENTER COMMAND: B Current Balance: 11 COMMAND MENU: Submit a Transaction (enter sequence of integers separated by spaces) Show Current [B]alance Show Number of [O]verdrafts [Q]uit Program ENTER COMMAND: o Number of Overdrafts: 2 COMMAND MENU: Submit a Transaction (enter sequence of integers separated by spaces) Show Current [B]alance Show Number of [O]verdrafts [Q]uit Program ENTER COMMAND: q ============ Thank you for using this App!!!! ============

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 Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions