Java Reference
In-Depth Information
amount = 50 + rand.nextInt(26); // Generate
amount of $50 to $75
transaction = new Transaction(accounts[select], // Account
TransactionType.CREDIT, // Credit
transaction
amount); // of amount
totalCredits[select] += amount;
// Keep total
credit tally
// Wait until the first clerk is free
while(clerk1.isBusy()) {
try {
Thread.sleep(25); // Busy so try
later
} catch(InterruptedException e) {
System.out.println(e);
}
}
clerk1.doTransaction(transaction); // Now do the
credit
// choose an account at random for debit operation
select = rand.nextInt(accounts.length);
amount = 30 + rand.nextInt(31); // Generate
amount of $30 to $60
transaction = new Transaction(accounts[select], // Account
TransactionType.DEBIT,
// Debit
transaction
amount);
// of amount
totalDebits[select] += amount;
// Keep total
debit tally
// Wait until the second clerk is free
while(clerk2.isBusy()) {
try {
Thread.sleep(25); // Busy so try
later
} catch(InterruptedException e) {
System.out.println(e);
}
}
clerk2.doTransaction(transaction); // Now do the
debit
}
Directory "BankOperation 3 - Multiple Accounts"
The last modification you must make to the method main() is for outputting the results. You now do this
in a loop, as you have to process more than one account:
Search WWH ::




Custom Search