1 Packageoo.day06;2 3 ImportJava.util.Scanner;4 5 Public classATM {6 7 UnionPay card;8 9 Public voidInsertcard (UnionPay card) {Ten One This. Card =Card; A } - - the Public voidPaytelbill () { - -Scanner input =NewScanner (system.in); - + if(CardinstanceofABC) { -ABC Card =(ABC) card; +System.out.println ("Please enter your phone number:"); AString Phonenum =Input.next (); atSystem.out.println ("Please enter the payment amount:"); - //Double number = double.parsedouble (Input.next ()); - DoubleNumber =input.nextdouble (); - - if(Card.paytelbill (Phonenum,number)) { - //System.out.println (Card.getbalance ()); inSYSTEM.OUT.PRINTLN ("Payment Success"); -}Else{ toSystem.out.println ("Payment failed"); + } - the}Else{ *System.out.println ("Your card is not an agricultural bank card and cannot be completed"); $ } Panax Notoginseng } - the + Public voidDrawmoney () { AScanner input =NewScanner (system.in); theSystem.out.println ("Please enter the amount to withdraw money:"); + DoubleNumber =input.nextdouble (); - if(Card.drawmoney (number)) { $ $System.out.println ("Take the money!") "); - } - } the - Public voidcheckpwd () {Wuyi theScanner input =NewScanner (system.in); -System.out.println ("Please Enter password:"); WuString Mima =Input.next (); -SYSTEM.OUT.PRINTLN ("Please select function:"); AboutSystem.out.println ("1. Check the balance 2. Withdrawals 3. Pay the phone fee"); $ intn =input.nextint (); - Switch(n) { - - Case1: A //card.getbalance (); + System.out.println (Card.getbalance ()); the Break; - Case2: $Drawmoney (); Break; the Case3: thePaytelbill (); Break; the } the - in } the the About the}
1 Packageoo.day06;2 3 4 //ABC card5 classAbcimplImplementsabc{6 7 PrivateString pwd;8 Private Doublebalance;9Abcimpl (String pwd,Doublebalance) {Ten One This. balance=balance; A This. PWD =pwd; - } - the - @Override - Public BooleanPaytelbill (String Phonenum,DoubleNumber ) { - + if(phonenum.length () = = && (balance-number) >=-2000){ - +balance-=Number ; A at return true; - } - Else - return false; - } - in @Override - Public Booleancheckpwd (String mima) { to if(Pwd.equals ("Mima")){ + - return true; the } * Else $ return false;Panax Notoginseng } - the @Override + Public BooleanDrawmoney (DoubleNumber ) { A if((Balance-number) >-2000){ theBalance-=Number ; + return true; - } $ Else $ return false; - } - the @Override - Public DoubleGetBalance () {Wuyi returnbalance; the } -}
Packageoo.day06;ImportJava.util.Scanner; Public classUnionpaytext { Public Static voidMain (string[] args) {ATM ATM=NewATM (); Abcimpl Card=NewAbcimpl ("123456", 2000); Atm.insertcard (card); Atm.checkpwd (); /*UNIONPAYICBC ICBC = new Icbcimpl ("123456", 3000); Scanner Scan =new Scanner (system.in); System.out.println ("Please enter password:"); String input = Scan.next (); Boolean str= icbc.checkpwd (input); System.out.println ("Please enter Amount:"); Double number = Scan.nextint (); Icbc.payonline (100); if (Icbc.drawmoney (number)) {System.out.println ("Take money successfully, the balance on the card is:" +icbc.getbalance ()); }*/ /*UnionPay ABC = new Abcimpl ("123456", 3000); Scanner Scann =new Scanner (system.in); System.out.println ("Please enter password:"); String INP = Scann.next (); Boolean str1= abc.checkpwd (INP); System.out.println ("Please enter Amount:"); Double number1 = Scann.nextint (); Icbc.payonline (100); if (Abc.drawmoney (Number1)) {System.out.println ("withdraw money successfully, the balance on the card is:" +abc.getbalance ()); } */ } }
Packageoo.day06; Public Interfaceunionpay{//Check Balance Doublegetbalance (); //Withdraw Money BooleanDrawmoney (DoubleNumber ); //Check Password Booleancheckpwd (String input);}InterfaceICBCextendsunionpay{//increased online payment capabilities Public voidPayonline (DoubleNumber ); }InterfaceAbcextendsunionpay{//increased online payment capabilities Public BooleanPaytelbill (String Phonenum,DoubleNumber ); }
ABC ATM Small case