{ public static void main(String[] args) { //创建一个客户对象 Scanner input = new Scanner(System.in); Customer c1 = new Customer(); c1.name ="客户1"; c1.tel = "10086"; c1.cid = "1010"; //创建一个账户 Account a1 = new Account(); a1.id = "001"; a1.balance = 200.0; //创建一个银行对象 BankClerk b1 = new BankClerk(); b1.open(c1,a1);//客户和账户进行绑定 c1.acc = a1 System.out.println("客户名:"+c1.name+ ",电话:" + c1.tel + ",身份证号:" + c1.cid + ",账号id是:"+c1.acc.id+ ",余额:" + c1.acc.balance); //第二个客户 Customer c2 = new Customer(); c2.name ="客户2"; c2.tel = "10010"; c2.cid = "0101"; //创建一个账户 Account a2 = new Account(); a2.id = "002"; a2.balance = 100.0; //创建一个银行对象 BankClerk b2 = new BankClerk(); b2.open(c2,a2);//客户和账户进行绑定 c1.acc = a1 System.out.println("客户名:"+c2.name+ ",电话:" + c2.tel + ",身份证号:" + c2.cid + ",账号id是:"+c2.acc.id+ ",余额:" + c2.acc.balance); c1.acc.withdraw(500); //取钱 System.out.println("客户名:"+c1.name+"余额:"+ c1.acc.balance); c1.acc.save(500); //存钱 System.out.println("客户名:"+c1.name+"余额:"+ c1.acc.balance); System.out.println("请输入转账金额:"); double a = input.nextDouble(); System.out.println("客户1转账给客户2请选择 1"); System.out.println("客户2转账给客户1请选择 2"); int b = input.nextInt(); switch (b){ case 1: if (a<= a1.balance) { c1.acc.transfer(a); c2.acc.accept(a); }else{ System.out.println("余额不足"); }break; case 2: if (a<=a2.balance){ c2.acc.transfer(a); c1.acc.accept(a); }else { System.out.println("余额不足"); }break; } //最后打印客户相关信息 System.out.println("客户名:"+c1.name+ ",电话:" + c1.tel + ",身份证号:" + c1.cid + ",账号id是:"+c1.acc.id+ ",余额:" + c1.acc.balance); System.out.println("客户名:"+c2.name+ ",电话:" + c2.tel + ",身份证号:" + c2.cid + ",账号id是:"+c2.acc.id+ ",余额:" + c2.acc.balance); } }
java实现银行转账
最新推荐文章于 2022-10-10 02:58:24 发布