每日代码系列(16)

 1 abstract class SIM {
 2   public abstract void setNumber(String n);
 3   public abstract String giveNumber();
 4   public abstract String giveCorpName();
 5 }
 6 class MobileTelephone {
 7   SIM card;
 8   public void useSIM(SIM card) {
 9     this.card=card;
10   }
11   public void showMess() {
12     System.out.println("使用的卡是:"+card.giveCorpName()+"提供的");
13     System.out.println("手机号码是:"+card.giveNumber());
14   }
15 }
16 class SIMOfChinaMobile extends SIM {
17   String number;
18   public void setNumber(String n) {
19     number=n;
20   }
21   public String giveNumber() {
22     return number;
23   }
24   public String giveCorpName() {
25     return "中国移动";
26   }
27 }
28 class SIMOfChinaUnicom extends SIM {
29   String number;
30   public void setNumber(String n) {
31     number=n;
32   }
33   public String giveNumber() {
34     return number;
35   }
36   public String giveCorpName() {
37     return "中国联通";
38   }
39 }
40 public class Example5_14 {
41   public static void main(String[] args) {
42     MobileTelephone telephone=new MobileTelephone();
43     SIM sim=new SIMOfChinaMobile();
44     sim.setNumber("13887656432");
45     telephone.useSIM(sim);
46     telephone.showMess();
47     sim=new SIMOfChinaUnicom();
48     sim.setNumber("13097656437");
49     telephone.useSIM(sim);
50     telephone.showMess();
51   }
52 }

 

上一篇:Educational Codeforces Round 83 --- F. AND Segments


下一篇:C# + Matlab 实现计件工时拟合