package com.yunruo;
//银行账户
public class Zhang {
String zhanghao;//账号
double yue;//余额
//构造方法
Zhang(String zh)
{
zhanghao = zh;
}
//同时存钱
Zhang(String zh,double ck)
{
zhanghao = zh;
yue += ck;
}
//成员方法
//存钱
//有参数无返回值
void cunQian(double ck)
{
yue += ck;
System.out.println("存入" + ck);
}
//取钱
//有参数有返回值
boolean quQian(double qk)
{
if (qk<= yue)
{
yue -=qk;
System.out.println("取出" + qk);
return true;
}
else
{
System.out.println("余额不足");
return false;
}
}
//获取余额
double getYue()
{
return yue;
}
//显示账号和余额
//无参数无返回值
void shouZhang()
{
System.out.println("账号 = " + zhanghao + "余额 = " + yue);
}
}
package com.yunruo;
public class Ceshilei {
public static void main(String[] args) {
// TODO 自动生成的方法存根
//测试Zhang
Zhang ac1 = new Zhang("123",1000);
ac1.cunQian(1000);
ac1.quQian(9000);
if (ac1.quQian(300))
{
System.out.println("取钱成功");
}
else
{
System.out.println("取钱失败");
}
}
}