1 package oo.day05; 2 3 4 5 6 7 public interface UnionPayABC{ 8 9 //查询余额 10 double getBalance(); 11 //取钱 12 boolean drawMoney(double number); 13 //检查密码 14 boolean checkPwd(String input); 15 } 16 17 18 19 interface ABC extends UnionPayABC { 20 //增加透支功能 21 public boolean payTelBill(String phoneNum,double sum); 22 } 23 24 //农行卡 25 class ABCImpl implements ABC{ 26 27 String pwd; 28 double balance; 29 ABCImpl(String pwd,double balance){ 30 31 this.balance=balance; 32 this.pwd = pwd; 33 } 34 35 36 @Override 37 public boolean payTelBill(String phoneNum, double sum) { 38 return false; 39 } 40 41 @Override 42 public boolean checkPwd(String input) { 43 if(pwd.equals("input")){ 44 45 return true; 46 } 47 else 48 return false; 49 } 50 51 @Override 52 public boolean drawMoney(double number) { 53 if((balance-number)>-2000){ 54 balance -= number; 55 return true; 56 } 57 else 58 return false; 59 } 60 61 @Override 62 public double getBalance() { 63 return balance; 64 } 65 }
1 package oo.day05; 2 3 4 public interface UnionPayICBC{ 5 6 //查询余额 7 double getBalance(); 8 //取钱 9 boolean drawMoney(double number); 10 //检查密码 11 boolean checkPwd(String input); 12 } 13 14 interface ICBC extends UnionPayICBC{ 15 //增加的在线支付功能 16 public void payOnline(double number); 17 18 19 } 20 21 22 23 //工商卡 24 class ICBCImpl implements ICBC{ 25 26 private String pwd; 27 private double balance; 28 29 ICBCImpl(String pwd,double balance){ 30 this.balance=balance; 31 this.pwd = pwd; 32 } 33 34 35 public void payOnline(double number) { 36 37 38 if(number<balance){ 39 40 balance-=number; 41 } 42 } 43 44 @Override 45 public boolean checkPwd(String input) { 46 if(pwd.equals("input")){ 47 48 return true; 49 } 50 else 51 return false; 52 } 53 54 @Override 55 public boolean drawMoney(double number) { 56 57 if(number<balance){ 58 59 balance-=number; 60 return true; 61 } 62 else 63 return false; 64 } 65 66 @Override 67 public double getBalance() { 68 69 70 return balance; 71 } 72 }
1 package oo.day05; 2 3 import java.util.Scanner; 4 5 public class UnionPayText { 6 7 8 public static void main(String[] args) { 9 /* 10 UnionPayICBC icbc = new ICBCImpl("123456",3000); 11 12 Scanner scan =new Scanner(System.in); 13 System.out.println("请输入密码:"); 14 15 String input = scan.next(); 16 boolean str= icbc.checkPwd(input); 17 System.out.println("请输入金额:"); 18 19 double number = scan.nextInt(); 20 21 //icbc.payOnline(100); 22 23 if(icbc.drawMoney(number)){ 24 25 System.out.println("取钱成功,卡上余额为:"+icbc.getBalance()); 26 27 }*/ 28 29 30 31 32 UnionPayABC abc = new ABCImpl("123456",3000); 33 34 Scanner scann =new Scanner(System.in); 35 System.out.println("请输入密码:"); 36 37 String inp = scann.next(); 38 boolean str1= abc.checkPwd(inp); 39 System.out.println("请输入金额:"); 40 41 double number1 = scann.nextInt(); 42 43 //icbc.payOnline(100); 44 45 if(abc.drawMoney(number1)){ 46 47 System.out.println("取钱成功,卡上余额为:"+abc.getBalance()); 48 49 } 50 51 } 52 53 } 54 55 56 57 58 59 60 61 62 63 64 65 66