Java实现简单的银行卡

Java实现简单的银行卡功能

  package com.company;

import javax.sound.midi.Soundbank;
import java.util.Date;


public class CardInfo {
    private String name;
    private  double balance;
    private String passwd;
//    public Date date;
    static  String bankName="中国银行";

    public CardInfo(String name,double balance,String passwd,Date date)
    {
        if(balance>0)
        {
            this.balance+=balance;
        }
        this.name=name;
        this.balance=balance;
        this.passwd=passwd;
        System.out.println("恭喜你开卡成功");
        System.out.println("账户信息:"+bankName+"您的余额为:"+this.balance);
        System.out.println("开户时间为+"+date.toLocaleString());
    }
    public String getName()
    {
        return name;
    }
    public void setName(String newName)
    {
        this.name=newName;
    }
    public double getBalance()
    {
        return this.balance;
    }

    public void setBalance(double balance)
    {
        this.balance=balance;
    }

    public String getPasswd()
    {
        return this.passwd;
    }

    //重置密码
    public void resetPasswd(CardInfo info,String newPasswd)
    {
        this.passwd=newPasswd;
        System.out.println("当前密码已更新为"+info.getPasswd());
    }
    //转账
    public void transform(CardInfo des,double amount)
    {
        if(this.balance>=amount)
        {
        this.balance-=amount;
        des.deposit(amount);
        }else
        {
            System.out.println(this.getName()+"账户余额不足");
        }
    }
    //取款
    public void withDraw(int amount)
    {
        if(amount<this.balance)
        {
            this.balance-=amount;
            System.out.println("取款成功"+amount+"元"+"您的剩余余额为"+this.getBalance()+"元");
        }else {
            System.out.println("余额不足");
        }
    }

    //存钱
    public void deposit(double amount)
    {
        if(amount<=0)
        {
            System.out.println("存入的钞票数额不对");
            return;
        }else {
            this.balance += amount;
        }
    }
    @Override
    public String toString()
    {
        return "账户信息"+"\t"+
                "银行:"+CardInfo.bankName+"\t"+
                "姓名:"+this.name+"\t"+
                "余额="+this.balance;
    }

    public void cardInfo()
    {
        System.out.println(this.toString());
    }
}
     
public class Main {

    public static void main(String[] args) {

        System.out.printf("给张三办卡");
        CardInfo zhangsan = new CardInfo("张三", 1000, "asd", new Date());
//        zhangsan.cardInfo();

        System.out.printf("给李四办卡");
        CardInfo lisi=new CardInfo("李四",2000,"zxc",new Date());
        System.out.println("张三给李四转账100块");
        zhangsan.transform(lisi,100);

        System.out.println("查询张三的余额");
        System.out.println("张三的余额为"+zhangsan.getBalance());

        System.out.println("查询李四的余额");
        System.out.println("李四的余额为"+lisi.getBalance());

    }
}

参考代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值