创建两个账户,两个客户,实现两个账户之间的转账

package zuoye;
import java.util.Scanner;
class Account{
    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 Customer{
    String name;
    String tel;
    String cid;
    Account account;
}
class Customer2{
    String name2;
    String tel2;
    String cid2;
    Account account2;
}
class BankClerk{
    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 = "1367";
        c2.cid= "987654321";
        Account a = new Account();
        a.id = "12345678910";
        a.balance = 0;
        Account a2 = new Account();
        a2.id = "01987654321";
        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(10000);
        c.account.save(20000);
        System.out.println(c.account.balance);
        c.account.withdraw(60000);
        System.out.println(c.account.balance);
        System.out.println("姓名:" + c2.name + ",电话:" + c2.tel + ",身份证号:" + c2.cid + ",账号:" + c2.account.id + ",余额:" + c2.account.balance);
        c2.account.save(40000);
        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();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值