超简单版模拟实现银行中用户存取款业务

//主要实现
public class Bank {
    static String bankName;//银行名称
    private String name;//储户名字
    private String password;//密码
    private double balance;//账户余额
    private double turnover;//交易额

    static void welcome()
    {
        System.out.println("欢迎您来到"+bankName);
    }


    public Bank(String name,String password,double turnover)
    {
        this.name = name;
        this.password=password;
        this.turnover = turnover;
        this.balance = turnover-10;

        System.out.println(name+"开户成功"+"余额为:"+balance);
    }
    //存款
    public void depoist(double turnover)
    {
        balance = balance+turnover;
        System.out.println(name+"您好,您的账户已存入"+balance+"元"+"当前余额为:"+balance+"元");
    }

    //取款
    public void withdrawl(String password,double turnover)
    {
        if(this.password!=password)
        {
            System.out.println("抱歉,你输入的密码有误");
            return ;
        }
        if(balance-turnover>0)
        {
            System.out.println("您已取出"+turnover+"元"+"当前余额为"+(balance-turnover));
        }
        else
        {
            System.out.println("抱歉,你的余额已不足");
        }
    }


    static void welcomenext()
    {
        System.out.println("请携带好您的随身物品,欢迎下次再来");
    }
}




//测试


public class Trade {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Bank.bankName="建设银行";
        Bank.welcome();
        Bank bank = new Bank("张华","123456",200.0);

        bank.depoist(200.0);
        bank.withdrawl("123456", 150.0);
        bank.withdrawl("333456", 150.0);
        bank.withdrawl("123456", 500.0);
        Bank.welcomenext();
    }
}

代码运算结果如下:
超简单版模拟实现银行中用户存取款业务_第1张图片

你可能感兴趣的:(Java)