码迷,mamicode.com
首页 > 其他好文 > 详细

银行卡系统 接口

时间:2016-09-18 23:53:07      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

  1 package card;
  2 //银行卡系统
  3 
  4 import java.util.Scanner;
  5 
  6 public class UnionPayTest {
  7     public static void main(String[] args) {
  8         UnionPay icbc = new ICBCImpl(2000,"123456");
  9         
 10         Scanner input = new Scanner(System.in);
 11         System.out.println("请输入密码:");
 12         if(icbc.checkPwd(input.next())){
 13             System.out.println("请输入金额:");
 14             double num = Double.parseDouble(input.next());
 15             if(icbc.drawMoney(num)){
 16                 System.out.println("取钱成功,卡余额为:"+icbc.getBalance());
 17             }
 18             else{
 19                 System.out.println("取钱失败");
 20             }
 21         }else{
 22             System.out.println("密码错误");
 23         }
 24 input.close();
 25     }
 26 }
 27 
 28 interface UnionPay {
 29     /**查看余额*/
 30     public double getBalance();    
 31     /**取钱*/
 32     public boolean drawMoney(double number);
 33     /**检查密码*/
 34     public boolean checkPwd(String input);
 35 }
 36 
 37 /**
 38  * 接口:用于描述工商银行发行的卡片功能,在满足
 39  * 银联的规则基础上,添加自己特有的功能
 40  */
 41 interface ICBC extends UnionPay {
 42     /**增加的在线支付功能*/
 43     public void payOnline(double number);
 44 }
 45 
 46 /**
 47  * 接口:用于描述中国农业银行发行的卡片功能,在满足
 48  * 银联的规则基础上,添加自己特有的功能
 49  */
 50 interface ABC extends UnionPay {
 51     /**增加支付电话费的功能*/
 52     public boolean payTelBill(String phoneNum,double sum);
 53 }
 54 
 55 
 56 
 57 /**
 58  * 类:用于描述工商银行实际发行的卡片
 59  * 该卡片具有的功能来自于继承的已经符合银联规范的ICBC接口
 60  */
 61 class ICBCImpl implements ICBC {
 62     private double money;
 63     private String pwd;
 64     
 65     public ICBCImpl(double money,String pwd){
 66         this.money = money;
 67         this.pwd = pwd;
 68     }
 69     
 70  
 71     public double getBalance() {        
 72         return money;
 73     }
 74     
 75     public boolean drawMoney(double number) {
 76         if(number <= money){
 77             money -=number;
 78             return true;
 79         }
 80         return false;
 81     }
 82    
 83     public void payOnline(double number) {
 84         if(number < money){
 85             money-=number;
 86         }
 87     }
 88     
 89     public boolean checkPwd(String input) {
 90         if(pwd.equals(input))
 91             return true;
 92         else
 93             return false;
 94     }
 95 }
 96 
 97 /**
 98  * 类:用于描述农业银行实际发行的卡片
 99  * 该卡片具有的功能来自于继承的已经符合银联规范的ABC接口
100  */
101 class ABCImpl implements ABC {
102     /**卡内余额,允许最多透支2000*/
103     private double balance;
104     /**账号密码*/
105     private String password;
106     
107     public ABCImpl(double balance,String password){
108         this.balance = balance;
109         this.password = password;
110     }
111     
112       
113     public double getBalance() {        
114         return balance;
115     }
116         
117   
118     public boolean drawMoney(double number) {
119         if((balance-number) >= -2000){
120             balance-=number;
121             return true;
122         }
123         return false;
124     }
125         
126     
127     public boolean checkPwd(String input) {
128         if(password.equals(input)){
129             return true;
130         }else{
131             return false;
132         }            
133     }
134         
135 
136     public boolean payTelBill(String phoneNum, double sum) {
137         if(phoneNum.length() == 11 && (balance-sum)>=-2000){
138             balance-=sum;
139             return true;
140         }
141         return false;
142     }
143 }

 

银行卡系统 接口

标签:

原文地址:http://www.cnblogs.com/luckyBrown/p/5883384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!