package java1;

public class Account {

String zhanghao;
double yue=0;
double add;
double get;
Account(String hao,double y)
{
zhanghao=hao;
yue=y;

}
double getAdd(double add)
{
yue+=add;
System.out.println("存钱"+add+"元,当余额为"+yue+"元");
return yue;
}

boolean getGet(double get)
{
if(get>yue)
{
System.out.println("取钱"+get+"元,当余额为"+yue+"元");
return true;
}
else
{
System.out.println("'余额不足");
return false;
}
}

//double getGet(double get)
//{
//yue-=get;
//System.out.println("取钱"+get+"元,当余额为"+yue+"元");
//return yue;
//}

double getYue()
{
System.out.println("账号为"+zhanghao+"当余额为"+yue+"元");
return yue;
}

}

Account a1= new Account("6000100020000", 500000);

a1.getAdd(10000);
a1.getGet(1);
a1.getYue();

 

首先定义一个描述银行账户的Account类,包括成员变 量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询”。其次, 编写一个主类,在主类中测试Account类的功能。(已完善)-LMLPHP

05-02 09:41