下面给出实现代码
在Account类中定义两个同步方法,draw和deposit
1package threads.sync; 2 3publicclass Account { 4private String accountNo; 5privatedouble balance; 6//if flag = false, means only deposit can be done 7privateboolean flag =false; 8public Account() {} 91011public Account(String accountNo,double balance) { 12this.accountNo = accountNo; 13this.balance = balance; 14 } 1516public String getAccountNo() { 17return accountNo; 18 } 1920publicvoid setAccountNo(String accountNo) { 21this.accountNo = accountNo; 22 } 2324publicdouble getBalance() { 25return balance; 26 } 2728publicvoid setBalance(double balance) { 29this.balance = balance; 30 } 313233publicint hashCode() { 34return accountNo.hashCode(); 35 } 3637publicboolean equals(Object obj) { 38if (this == obj)returntrue; 39if (obj !=null && obj.getClass() == Account.class) { 40 Account target = (Account)obj; 41return target.getAccountNo().equals(accountNo); 42 } 43returnfalse; 44 } 4546publicsynchronizedvoid draw(double drawAmount) { 47try {