如何用Java代码编写银行转账

Python0130

如何用Java代码编写银行转账,第1张

public interface ITransfer{ /* * 银行内部转账,从转出账号中扣除转账金额,给转入账号增加转账金额,需要保证以上两个操作 * 要么同时成功,要么同时失败 * fromAccountId 转出账号 * outAccountId 转入账号 * amount 转账金额 */ public void transferInner(String fromAccountId,String outAccountId,BigDecimal amount) /* * 外部转账-转出,从转出账号中扣除转账金额 * fromAccoutnId 转出账号 * amount 转账金额 */ public void transferOut(String fromAccountId,String outAccountId,BigDecimal amount) /* * 外部转账-转入,从转入账号中增加转账金额 * toAccoutnId 转出账号 * amount 转账金额 */ public void transerIn(String toAccountId,BigDecimal amount) } public interface ITransfer{ /* * 银行内部转账,从转出账号中扣除转账金额,给转入账号增加转账金额,需要保证以上两个操作 * 要么同时成功,要么同时失败 * fromAccountId 转出账号 * outAccountId 转入账号 * amount 转账金额 */ public void transferInner(String fromAccountId,String outAccountId,BigDecimal amount)/* * 外部转账-转出,从转出账号中扣除转账金额 * fromAccoutnId 转出账号 * amount 转账金额 */ public void transferOut(String fromAccountId,String outAccountId,BigDecimal amount)/* * 外部转账-转入,从转入账号中增加转账金额 * toAccoutnId 转出账号 * amount 转账金额 */ public void transerIn(String toAccountId,BigDecimal amount)}

public void zhuanzhang(person p1,person p2,int i){

            p1.money=p1.money-i

            if(p1.money<0){

                p1.money=p1.money+i

                new Exception("金额不足")

            }

            p2.money=p2.money+i

        }

很简单啊

这边减少的等于另一边增加的金额

这要用线程进行设计

减少和增加要同时进行

否则 银行要亏死

你想想A给B转账:

A钱转过去了,加到B的账户上,但A账户的钱没有减少(出了故障)

或者

A钱转过去了,A账户的钱减少,但B账户的钱没有增加(出了故障)

如果是这样银行怎么开下去啊