首页 > 代码库 > 练习1:创建一个简单的银行程序包

练习1:创建一个简单的银行程序包

package banking;public class Account {        private double balance;    public Account(double balance)    {        this.balance=balance;    }    public double getBalance() {        System.out.println("当前余额为:"+balance+"元");        return balance;    }        public double deposit(double add){        balance+=add;        System.out.println("存钱"+add+"元,当余额为"+balance+"元");        return balance;    }            boolean    withdraw(double get){        if(get<=balance)        {            System.out.println("取钱"+get+"元,当余额为"+balance+"元");            return true;        }        else        {            System.out.println("‘余额不足");            return false;        }                }}

技术分享

 

练习1:创建一个简单的银行程序包