- java 类的应用-模拟银行存取款
public class Card { String id = "1451151154121"; static int yue = 10000; public Card() //无参数的构造方法 { } void cunqian(int cunkuan) //存钱方法cunqian,存款数cunkuan { yue = yue + cunkuan; //余额=余额+存款数 System.out.println("存入"+cunkuan+"元。"); } void quqian(int qukuan) //取钱方法quqian,取钱数qukuan { yue = yue - qukuan; //余额=余额-取款数 System.out.println("取出"+qukuan+"元。"); } public static void main(String arg[]){ Card xxx = new Card(); //*无参数*创建卡xxx,初始值-卡号:1451451154121,余额10000 int c = 2300,d = 2300; xxx.cunqian(c); //取钱 xxx.quqian(d); //存钱 int biandong = c - d; if(biandong > 0) { System.out.print("您好,卡号为"+xxx.id+"的用户,您的账户增加"+biandong+"元,余额"+Card.yue+"元"); //输出xxx卡的卡号和余额 } else if(biandong == 0) { System.out.print("您好,卡号为"+xxx.id+"的用户,您的账户变动"+biandong+"元,余额"+Card.yue+"元"); //输出xxx卡的卡号和余额 } else { System.out.print("您好,卡号为"+xxx.id+"的用户,您的账户减少"+biandong+"元,余额"+Card.yue+"元"); //输出xxx卡的卡号和余额 } }}