試試看
該銀行計算機是對帳戶執行操作的代理
//Define the bank
class Bank
{
//Perform a tranaaction
public void doTransaction(Transaction transaction)
{
int balance=transaction
{
switch(transaction
{
case Transaction
{
case Transaction
//Credits require a lot of checks
try
{
Thread
}
catch(InterruptedException e)
(
system
}
balance =transaction
case Transaction
//Debits require even ore checks
try
{
Thread
}
catch(InterruptedException e)
{
system
}
blance +transaction
break;
default; //we should never get here
system
return types[transactionType]+
}
private Account account
private int amount;
private int transactionType
}如何工作
一個交易的識別是由transactionType域指定的
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27749.html