1 package com.hanqi; 2 3 public class Account { 4 5 String ZhangHao; 6 7 double CunKuanYuE; 8 9 Account(String ZhangHao,double CunKuanYuE) 10 { 11 //初始化 12 this.ZhangHao = ZhangHao; 13 this.CunKuanYuE = CunKuanYuE; 14 } 15 16 //存款 17 //无返回值带参数的方法 18 void cunKuan (double qianshu) 19 { 20 System.out.println("存了" + qianshu); 21 this.CunKuanYuE += qianshu; 22 } 23 24 //取款 25 //无返回值带参数的方法 26 void quKuan (double qianshu) 27 { 28 System.out.println("取了" + qianshu); 29 this.CunKuanYuE -= qianshu; 30 } 31 //查询余额 32 //有返回值无参数的方法 33 34 double getYuE() 35 { 36 return this.CunKuanYuE; 37 } 38 39 40 public static void main(String[] args) 41 { 42 Account ac = new Account("123456",1000); 43 44 ac.cunKuan(100); 45 System.out.println("查询余额=" + ac.getYuE()); 46 47 ac.quKuan(300); 48 System.out.println("查询余额=" + ac.getYuE()); 49 50 } 51 52 }
时间: 2024-11-11 03:05:18