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(); } }
时间: 2024-12-21 12:11:05