package cn.vscoder.experiment_3.reader;

public class Reader {
    public int readerID;
    protected String readerName;
    protected String readerPwd;
    protected double balance;

    private static int nextReaderID;

    static{
        nextReaderID=10001;
    }

    public Reader() {
        readerID=nextReaderID++;
        readerName="";
        readerPwd="666666";
        balance=0;
    }

    public Reader(String readerName) {
        this();
        this.readerName = readerName;
    }

    public int getReaderID() {
        return readerID;
    }

    public String getReaderName() {
        return readerName;
    }

    public String getReaderPwd() {
        return readerPwd;
    }

    public double getBalance() {
        return balance;
    }
    //修改密码，密码必须为6位
    public void changePwd(String oldPwd,String newPwd){
        if (oldPwd.equals(this.readerPwd)){
            if (newPwd.length()==6){
                this.readerPwd=newPwd;
                System.out.println("密码修改成功！");

            }else{
                System.out.println("密码必须为6位！");
            }
        }
    }
    //充值功能。充值不能小于0
    public void setBalance(double balance) {//充值
        if (balance<0){
            System.out.println("充值金额不能小于0！");
        }else {
        this.balance += balance;}
    }
    @Override
    public String toString() {
        return "读者信息：" +
                "readerID=" + readerID +
                ", 读者姓名='" + readerName + '\'' +
                ", 密码='" + readerPwd + '\'' +
                ", 余额=" + balance ;
    }
}
