日期:2014-05-20 浏览次数:20687 次
class Bank { private Account[] account; private boolean locked; public Bank() { account = new Account[100]; for(int i = 0; i < account.length; i++) { account[i] = new Account(); } locked = false; } public void transferMoney(int accountNumber, float amount) { while(locked); locked = true; float oldBalance = account[accountNumber].getBalance(); float newBalance = oldBalance + amount; account[accountNumber].setBalance(newBalance); locked = false; } }