标签:
1.Account类
package lianxi; public class Account { String zhanghao; Double cunkuanyu_e; Account (String hao,Double a) { zhanghao=hao; cunkuanyu_e=a; } void cunkuan(Double cunqian) { cunkuanyu_e+=cunqian; System.out.println("存钱"+cunqian+"元后存款余额为:"+cunkuanyu_e); } void qukuan(Double quqian) { cunkuanyu_e-=quqian; System.out.println("取钱"+quqian+"元后存款余额为:"+cunkuanyu_e); } void yu_echaxun() { System.out.println("帐号 "+zhanghao+" 余额为 "+cunkuanyu_e+"元"); } }
2.main
package lianxi; public class Ceshi { public static void main(String[] args) { Account yinhang=new Account("1234567890123", 20000.0); yinhang.cunkuan(500.0); yinhang.qukuan(700.0); yinhang.yu_echaxun(); } }
首先定义一个描述银行账户的Account类,包括成员变 量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询”。其次, 编写一个主类,在主类中测试Account类的功能。
标签:
原文地址:http://www.cnblogs.com/wenwen123/p/5499893.html