Java面向对象,实现银行账户转账

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();
        }
    }



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值