进行银行转账

package day_13;
class Account{//创建一个账号
    String id;//账号id
    double balance;//账户余额
    Customer customer;

    public void save(double money){//存钱方法
        if (money>0){//输入的参数需要大于0
            balance+=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;
        }
    }

    public void transfer(Customer a,Customer b,Account c,Account d,double accounts){
        a.account=c;
        c.customer=a;
        b.account=d;
        d.customer=b;
        if (c.balance>=100){
            c.balance-=accounts;
            d.balance+=accounts;
        }else{
            System.out.println("您的余额不足。");
        }


    }


}

class Customer {     //客户类
    String name;    //姓名
    String tel;     //手机号
    String cid;     //身份证号码
    Account account;    //客户的账号
}
class BankClerk{//银行类
    //Customer c 客户类的对象 具体的某人
    //Account  a 创建了一个账户a 账户类的对象  具体的某一个账户
    public void  open(Customer c,Account a){  //开户
        //客户和账户进行绑定   给客户c开了一个账户a
        c.account=a;
        a.customer=c;
}
}

public class Method_Exer06 {
    public static void main(String[] args) {
        //创建客户对象
        Customer c=new Customer();
        c.name="周强";
        c.tel="110";
        c.cid="10086";

        //创建一个账户
        Account a=new Account();
        a.id="007";
        a.balance=0;

        //创建一个银行对象  让他们进行绑定
        BankClerk b=new BankClerk();
        b.open(c,a);//客户和账户进行绑定
        System.out.println("客户名:"+a.customer.name+";电话:"+a.customer.tel+";身份证:"+a.customer.cid+";账户是:"+c.account.id+";账户余额:"+c.account.balance);

        //周强取钱
        c.account.withdraw(500);

        //存钱
        c.account.save(1000);
        System.out.println(c.account.balance);

        //周强取钱
        a.withdraw(1000);
        System.out.println(a.balance);

        //转账
        Customer i=new Customer();
        Customer u=new Customer();
        Account x=new Account();
        x.balance=1000;
        Account y=new Account();
        y.balance=100;
        System.out.println("转账前:"+x.balance);
        System.out.println("转账前:"+y.balance);

        Account z=new Account();
        z.transfer(i,u,x,y,100);
        System.out.println("转账后:"+x.balance);
        System.out.println("转账后:"+y.balance);
    }
}
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值