package day14; import java.util.Scanner; class Account01 { String id; String id2; double balance; double balance2; public void save(double money){ if(money > 0){ balance += money; }else{ System.out.println("参数有误"); } if(money > 0){ balance2 += money; }else{ System.out.println("参数有误"); } } public void withdraw(double money){ if(money <0){ System.out.println("参数有误"); }else if(money > balance){ System.out.println("余额不足"); }else{ balance -= money; } if(money <0){ System.out.println("参数有误"); }else if(money > balance2){ System.out.println("余额不足"); }else{ balance2 -= money; } } } class Customer02{ String name; String tel; String cid; Account account; } class Customer2{ String name2; String tel2; String cid2; Account account2; } class BankClerk03 { public void open(Customer c, Account a){//开户 c.account = a; } } class BankClerk2{ class Niubility { public void open(Customer c2, Account a2){ c2.account = a2; } } public static void main(String[] args) { Customer c = new Customer(); c.name = "仁之平"; c.tel = "7534"; c.cid = "123456789"; Customer c2= new Customer(); c2.name = "简韩嘉"; c2.tel = "1011"; c2.cid= "51515161"; Account a = new Account(); a.id = "65465258"; a.balance = 0; Account a2 = new Account(); a2.id = "4645651"; a2.balance = 0; BankClerk b = new BankClerk(); b.open(c, a); BankClerk b2 = new BankClerk(); b.open(c2, a2); System.out.println("姓名:" + c.name + ",电话:" + c.tel + ",身份证号:" + c.cid + ",账号:" + c.account.id + ",余额:" + c.account.balance); c.account.withdraw(20000); c.account.save(26000); System.out.println(c.account.balance); c.account.withdraw(30000); System.out.println(c.account.balance); System.out.println("姓名:" + c2.name + ",电话:" + c2.tel + ",身份证号:" + c2.cid + ",账号:" + c2.account.id + ",余额:" + c2.account.balance); c2.account.save(60000); System.out.println(c2.account.balance); Scanner sc=new Scanner(System.in); System.out.println("请输入要转出的账户"); String outName= sc.next(); System.out.println("请输入要转入的账户"); String intName= sc.next(); System.out.println("请输入转账的金钱"); int maney2=sc.nextInt(); } }
Java面向对象,实现银行账户转账
于 2022-09-23 08:47:09 首次发布