标签:
编写Java应用程序。首先定义一个描述银行账户的Account类,包括成员变
量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询”。其次,
编写一个主类,在主类中测试Account类的功能。
类:
1 String bankAccountNumber; 2 String name; 3 double cunKuanYu_e; 4 double cunKuan; 5 double quKuan; 6 double yu_E_ChaXun; 7 8 void cunkuan(double cunkuan) { 9 yu_E_ChaXun = cunKuanYu_e + cunkuan; 10 cunKuanYu_e = yu_E_ChaXun; 11 System.out.println(name + "你的账号为:" + bankAccountNumber + "的账户中存入" + cunkuan + "元,现有余额" + yu_E_ChaXun); 12 } 13 14 void qukuan(double qukuan) { 15 yu_E_ChaXun = cunKuanYu_e - qukuan; 16 if (yu_E_ChaXun >= 0) { 17 cunKuanYu_e = yu_E_ChaXun; 18 System.out.println(name + "你的账号为:" + bankAccountNumber + "的账户中取出" + qukuan + "元,现有余额" + yu_E_ChaXun); 19 } else { 20 System.out.println(name + "你的账号为:" + bankAccountNumber + "的账户中余额不足!"); 21 } 22 } 23 24 void yu_echaxun(double ck, double qk) { 25 26 double yu_E_ChaXun = cunKuanYu_e + ck - qk; 27 if (yu_E_ChaXun >= 0) { 28 cunKuanYu_e=yu_E_ChaXun; 29 System.out.println(name + "你的账号为:" + bankAccountNumber + "的账户中余额=" + yu_E_ChaXun); 30 } else { 31 System.out.println(name + "你的账号为:" + bankAccountNumber + "的账户中余额不足"); 32 } 33 }
调用:
1 Account ren1=new Account(); 2 ren1.bankAccountNumber="622848123456789"; 3 ren1.name="张三"; 4 ren1.cunKuanYu_e=587.54; 5 6 ren1.qukuan(600.0); 7 ren1.cunkuan(1000); 8 ren1.yu_echaxun(280, 150); 9 ren1.yu_echaxun( 0, 200); 10 11 Account ren2=new Account(); 12 ren2.bankAccountNumber="622848987654321"; 13 ren2.name="李四"; 14 ren2.cunKuanYu_e=87.54; 15 16 ren2.yu_echaxun(600, 7000); 17 ren2.yu_echaxun(600,0);
结果:
标签:
原文地址:http://www.cnblogs.com/ouyangtangfeng99/p/5500232.html