Hi all
I need some help please with Java and arrays.
I have two arrays: customerID and transactionValue (they are pairs so each transaction has a customer ID and a customer may have made several transactions).
The arrays generate random numbers for the customers and associated transaction values.
The number of elements in each array has an int variable called ‘size’.
I have successfully written the code that can display the customers and the transaction values, for example:
Customer ID, Transaction Value
2, 45.2
1, 55.2
3, 10.3
3, 20
0, 400.2
4, 100.30
3, 50.5
I need to work out, and display (using loops and ‘if’ statements, not allowed to create any other arrays or lists): for each customer I need to display the number of transactions that are on the list.
So I am trying now to write code (based on the numbers above) that produces this following output:
Customer: 2, Transactions:1
Customer: 1, Transactions: 1
Customer: 3, Transactions 3
Customer: 0, Transactons: 1
Customer: 4, Transactions: 1
So I thought I could use variable (int for customer ID and double for transaction values) to “go through the array and count the number of times that for example customer 0 is represented, when that is done do the loop again and see how many times customer 1 is represented and so on”.
My initial thoughts but I may be totally wrong, and clearly I need more code:
I have been struggling for hours so any pointers would be most welcome- thanksint count=0; int thisValue; for (index=0;index<size;index++){ for (thisValue=0;thisValue<size;thisValue++){ if (customerID[index]==thisValue){ count=count++; } } } System.out.println ("The count is= "+count); }