public static void main(String[] args) { Customer c1 = new Customer(); c1.name = "福珠"; c1.tel = "118"; c1.cid = "10086"; Customer c2 = new Customer(); c2.name = "周茨"; c2.tel = "110"; c2.cid = "10077"; Account a1 = new Account(); a1.id = "001"; a1.balance = 0; Account a2 = new Account(); a2.id = "002"; a2.balance = 0; class Banklerk { public void open(Customer c,Account a){ c.account=a; } } Banklerk b1 = new Banklerk(); b1.open(c1, a1); System.out.println("客户名:" + c1.name + ";账户ID是:" + c1.account); Banklerk b2 = new Banklerk(); b2.open(c2, a2); System.out.println("客户名:" + c2.name + ";账户ID是:" + c2.account); c1.account.save(1000);//原本就有的账户余额 c2.account.save(1500); System.out.println(c1.name+"的余额为"+c1.account.balance);//打印余额; //周全取钱 c2.account.withdraw(800); System.out.println(c2.name+"取了800元,所以"+c2.name+"的余额为"+c2.account.balance);//打印余额 a1.withdraw(100);//可以直接得出转账后的余额 a2.save(100); System.out.println(c1.name+"给"+c2.name+"转账100元"); System.out.println(c1.name+"的余额为"+c1.account.balance); System.out.println(c2.name+"的余额为"+c2.account.balance); } }
实现账户转账,同时更新数据
于 2022-09-23 08:30:37 首次发布