逆袭之旅DAY09.东软实训.接口

 

2018年7月5日

 

 1 package day0705.teacher.test1usb;
 2 /**
 3  * 测试类
 4  * @author Administrator
 5  *
 6  */
 7 public class UsbInterfaceTest {
 8 
 9     /**
10      * @param args
11      */
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         
15         UsbFan uf = new UsbFan();
16         uf.service();
17         
18         //让一个接口引用指向实现了接口的类
19         UsbInterface ui = new UsbFan();
20         ui.service();
21         
22         ui = new UsbDisk();
23         ui.service();
24         
25         //1.U盘
26         UsbInterface uDisk = new UsbDisk();
27         uDisk.service();
28         
29         //2.风扇
30         UsbInterface uF = new UsbFan();
31         uf.service();
32         
33         
34         
35     }
36 
37 }

 

 1 package day0705.teacher.test2printer;
 2 /**
 3  * 打印机类
 4  * @author Administrator
 5  *
 6  */
 7 public class Printer {
 8     /**
 9      * 使用墨盒在纸张上打印
10      * @param inkbox 打印使用的墨盒
11      * @param paper 打印使用的纸张
12      */
13     public void print(InkBox inkbox,Paper paper){
14         System.out.println("使用"+inkbox.getColor()+"在"+paper.getSize()+"上打印");
15     }
16     
17 }
 1 package day0705.teacher.test2printer;
 2 /**
 3  * 测试类
 4  * @author Administrator
 5  *
 6  */
 7 public class PrinterTest {
 8 
 9     /**
10      * @param args
11      */
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         //1、定义打印机
15         Printer p = new Printer();
16         
17         InkBox inkbox =null;
18         Paper paper = null;
19         
20         //测试打印机的功能
21         //准备黑色墨盒和A4纸
22         inkbox = new GrayInkBox();
23         paper = new A4();
24         //开始打印
25         p.print(inkbox, paper);
26         
27         //准备彩色墨盒和A5纸
28         inkbox = new ColorInkBox();
29         paper =new A5Paper();
30         //开始打印
31         p.print(inkbox, paper);
32         
33         
34         
35     }
36 
37 }

 

 

 1 package day0705.teacher.test4softenginner;
 2 
 3 /**
 4  * 软件工程师
 5  * @author Administrator
 6  *
 7  */
 8 public class SoftEnginner implements Programmer, BizAgent {
 9     //软件工程师的姓名
10     private String name;
11     
12     public SoftEnginner(String name){
13         this.name= name;
14     }
15     
16     /**
17      * 自我介绍
18      */
19     public String getName() {
20         // TODO Auto-generated method stub
21         return name;
22     }
23     
24     /**
25      * 讲业务的能力
26      */
27     public void giveBizSpeech() {
28         // TODO Auto-generated method stub
29         System.out.println("我会讲业务。");
30     }
31 
32     /**
33      * 编程能力
34      */
35     public void WriteProgram() {
36         // TODO Auto-generated method stub
37         System.out.println("我会编程。");
38 
39     }
40 
41 }
 1 package day0705.teacher.test4softenginner;
 2 /**
 3  * 测试类
 4  * @author Administrator
 5  *
 6  */
 7 public class Test {
 8 
 9     /**
10      * @param args
11      */
12     public static void main(String[] args) {
13         // TODO Auto-generated method stub
14         
15         //1、创建软件工程师对象
16         SoftEnginner xiaoming = new SoftEnginner("小明");
17         System.out.println("我是一名软件工程师,我的名字是"+xiaoming.getName()+"。");
18         
19         //2、软件工程师进行代码的编写
20         xiaoming.WriteProgram();
21         
22         //3、软件工程师进行业务讲解
23         xiaoming.giveBizSpeech();
24         
25     }
26 
27 }

 

 

******************************************************************************************************************************************* ******************************************** 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

比的是地址,对象

比较两个猫的大小

字符串比大小

******************************************************************************************************************************************* ******************************************** 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

******************************************************************************************************************************************* ******************************************** 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

******************************************************************************************************************************************* ******************************************** 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

第3,4题

 1 package day0705.work.test5;
 2 
 3 public class Store {
 4     
 5     public static Animal get(String choice){
 6         
 7         //equalsIgnoreCase  判断两个字符串是否一致,忽略大小写
 8         /*
 9          * 判断传入的字符
10          *         如果是"dog"   返回一个Dog对象
11          *         如果是"pig"   返回一个Pig对象
12          *         否则返回Cat对象
13          */
14         if(choice.equalsIgnoreCase("dog")){
15             return new Dog();
16         } else if(choice.equalsIgnoreCase("pig")){
17             return new Pig();
18         }else{
19             return new Cat();
20         }
21     }
22 
23 }
 1 package day0705.work.test5;
 2 
 3 public class AnimalTest {
 4 
 5     /**
 6      * @param args
 7      */
 8     public static void main(String[] args) {
 9         // TODO Auto-generated method stub
10         
11         //???
12         Animal al = Store.get("dog");
13         al.shout();
14         
15         al = Store.get("Pig");
16         al.shout();
17         
18         
19     }
20 
21 }

 

年轻人能为世界年轻人能为世界做些什么
原文地址:https://www.cnblogs.com/twinkle-star/p/9266687.html