2018年7月5日
package day0705.teacher.test1usb;
/**
* 测试类
* @author Administrator
*
*/
public class UsbInterfaceTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub UsbFan uf = new UsbFan();
uf.service(); //让一个接口引用指向实现了接口的类
UsbInterface ui = new UsbFan();
ui.service(); ui = new UsbDisk();
ui.service(); //1.U盘
UsbInterface uDisk = new UsbDisk();
uDisk.service(); //2.风扇
UsbInterface uF = new UsbFan();
uf.service(); } }
package day0705.teacher.test2printer;
/**
* 打印机类
* @author Administrator
*
*/
public class Printer {
/**
* 使用墨盒在纸张上打印
* @param inkbox 打印使用的墨盒
* @param paper 打印使用的纸张
*/
public void print(InkBox inkbox,Paper paper){
System.out.println("使用"+inkbox.getColor()+"在"+paper.getSize()+"上打印");
} }
package day0705.teacher.test2printer;
/**
* 测试类
* @author Administrator
*
*/
public class PrinterTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//1、定义打印机
Printer p = new Printer(); InkBox inkbox =null;
Paper paper = null; //测试打印机的功能
//准备黑色墨盒和A4纸
inkbox = new GrayInkBox();
paper = new A4();
//开始打印
p.print(inkbox, paper); //准备彩色墨盒和A5纸
inkbox = new ColorInkBox();
paper =new A5Paper();
//开始打印
p.print(inkbox, paper); } }
package day0705.teacher.test4softenginner; /**
* 软件工程师
* @author Administrator
*
*/
public class SoftEnginner implements Programmer, BizAgent {
//软件工程师的姓名
private String name; public SoftEnginner(String name){
this.name= name;
} /**
* 自我介绍
*/
public String getName() {
// TODO Auto-generated method stub
return name;
} /**
* 讲业务的能力
*/
public void giveBizSpeech() {
// TODO Auto-generated method stub
System.out.println("我会讲业务。");
} /**
* 编程能力
*/
public void WriteProgram() {
// TODO Auto-generated method stub
System.out.println("我会编程。"); } }
package day0705.teacher.test4softenginner;
/**
* 测试类
* @author Administrator
*
*/
public class Test { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub //1、创建软件工程师对象
SoftEnginner xiaoming = new SoftEnginner("小明");
System.out.println("我是一名软件工程师,我的名字是"+xiaoming.getName()+"。"); //2、软件工程师进行代码的编写
xiaoming.WriteProgram(); //3、软件工程师进行业务讲解
xiaoming.giveBizSpeech(); } }
******************************************************************************************************************************************* ********************************************
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
比的是地址,对象
比较两个猫的大小
字符串比大小
******************************************************************************************************************************************* ********************************************
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
******************************************************************************************************************************************* ********************************************
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
******************************************************************************************************************************************* ********************************************
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
第3,4题
package day0705.work.test5; public class Store { public static Animal get(String choice){ //equalsIgnoreCase 判断两个字符串是否一致,忽略大小写
/*
* 判断传入的字符
* 如果是"dog" 返回一个Dog对象
* 如果是"pig" 返回一个Pig对象
* 否则返回Cat对象
*/
if(choice.equalsIgnoreCase("dog")){
return new Dog();
} else if(choice.equalsIgnoreCase("pig")){
return new Pig();
}else{
return new Cat();
}
} }
package day0705.work.test5; public class AnimalTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub //???
Animal al = Store.get("dog");
al.shout(); al = Store.get("Pig");
al.shout(); } }