package com.hanqi;
//账户类
public class Account {
String ZhangHao;
double CunKuanYuE;
Account(String ZhangHao,double CunKuanYuE)
{
//初始化
this.ZhangHao=ZhangHao;
this.CunKuanYuE=CunKuanYuE;
}
//存款,并得到余额
//无返回值带参数的方法
double cunkuan(double qianshu)
{
//验证
if(qianshu<0)
{
System.out.println("钱数错误");
//
}
else{
System.out.println("存了"+qianshu);
this.CunKuanYuE+=qianshu;
}
return this.CunKuanYuE;
}
//取款
//无返回值带参数的方法
void qukuan(double qianshu)
{
//验证
if(qianshu<0)
{
System.out.println("余额不足");
//
return;
}
System.out.println("取了"+qianshu);
this.CunKuanYuE-=qianshu;
}
//查询余额
//有返回值无参数的方法
double getYuE()
{
return this.CunKuanYuE;
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Account ac=new Account("123456", 1000);
ac.cunkuan(1000);
System.out.println("查询余额"+ac.getYuE());
ac.qukuan(300);
System.out.println("查询余额"+ac.getYuE());
}
}
![](https://images2015.cnblogs.com/blog/917895/201605/917895-20160517141959357-1021948739.png)