学习练习 java面向对象存取款查询余额

时间:2021-10-27 13:13:25
 package com.hanqi;

 public class Account {

     String ZhangHao;

     double CunKuanYuE;

     Account(String ZhangHao,double CunKuanYuE)
{
//初始化
this.ZhangHao = ZhangHao;
this.CunKuanYuE = CunKuanYuE;
} //存款
//无返回值带参数的方法
void cunKuan (double qianshu)
{
System.out.println("存了" + qianshu);
this.CunKuanYuE += qianshu;
} //取款
//无返回值带参数的方法
void quKuan (double qianshu)
{
System.out.println("取了" + qianshu);
this.CunKuanYuE -= qianshu;
}
//查询余额
//有返回值无参数的方法 double getYuE()
{
return this.CunKuanYuE;
} public static void main(String[] args)
{
Account ac = new Account("123456",1000); ac.cunKuan(100);
System.out.println("查询余额=" + ac.getYuE()); ac.quKuan(300);
System.out.println("查询余额=" + ac.getYuE()); } }

学习练习 java面向对象存取款查询余额