1String Zhanghu;//Define Account2 DoubleCunkuanyue;//Define Deposit Balances3Account (String Zhanghu,DoubleCunkuanyue)//Initialize account, deposit balance4 {5 //This . Represents the current class6 This. zhanghu=Zhanghu;7 This. cunkuanyue=Cunkuanyue;8 }9 //DepositTen //methods with parameters for return values One DoubleCunkuan (DoubleQianshu) A { - //Validation - if(Qianshu < 1) the { -SYSTEM.OUT.PRINTLN ("Input Error"); - - } + Else - { +System.out.println ("Saved" +Qianshu); A This. Cunkuanyue + =Qianshu; at } - return This. Cunkuanyue; - } - - - in //Withdrawals - //methods with parameters for return values to DoubleQukuan (DoubleQianshu) { + if(Qianshu > This. Cunkuanyue) { -SYSTEM.OUT.PRINTLN ("Insufficient balance"); the *}Else { $System.out.println ("took" +Qianshu);Panax Notoginseng This. Cunkuanyue-=Qianshu; - } the return This. Cunkuanyue; + } A //Check Balance the //methods with no parameters for return values + DoubleGetyue () - { $ return This. Cunkuanyue; $ } - - the Public Static voidMain (string[] args) { - //TODO Auto-generated method stubsWuyiAccount account=NewAccount ("123456", 1000); theAccount.cunkuan (100); -System.out.println ("Check balance" +Account.getyue ()); WuAccount.qukuan (300); -System.out.println ("Check balance" +Account.getyue ()); About}
Object-oriented-deposit and withdrawal