2. 定义一个类实现银行帐户的概念,包括的变量有"帐号"和"存款余额",包括的方法有"存款"、"取款"、"查询余额"和”显示帐号”,。定义主类,创建帐户类的对象,并完成相应操作。
提示:关键代码如下:
public int getleftmoney(){
return leftmoney;
}
public void savemoney(double money){
leftmoney+=money;
}
public void getmoney(double money){
if(money<=leftmoney)
leftmoney-=money;
else
System.out.println("只能取:"+leftmoney);
}
…
bankaccount ba=new bankaccount(888123,1000);
ba.savemoney(21000);
System.out.println("存入21000元后余额为:"+ba.getleftmoney());
ba.getmoney(11500);
System.out.println("11500元后余额为:"+ba.getleftmoney());