1. 用接口思想编程解题,具体要求如下:
(1) 所有的可以拨号的设备都应该有拨号功能(Dailup)。
(2) 所有的播放设备都可以有播放功能(Play)。
(3) 所有的照相设备都有拍照功能(takePhoto)。
(4) 定义一个手机类 Mobile, 有拨号,拍照,播放功能。
(5) 定义一个人类 Person, 有如下方法:
a.使用拨号设备 use (拨号设备)
b.使用拍照设备 use(拍照设备)
c.使用播放设备 use(播放设备)
(6) 编写测试类Test ,创建人使用这些对象。
测试类参考样式:
张学友用手机拨打了18988889999的号码,手机自拍了一张巡回演唱会的照片,并用手机播放了《一路上有你》的歌曲。
//三个接口
public interface Dailup {
void dailup();
}
public interface Play {
void play();
}
public interface Takephoto {
void takephoto();
}//Mobile类
public class Mobile implements Dailup,Play,Takephoto{
public void dailup(){
System.out.println("张学友用手机拨打了18988889999的号码,");
}
public void play(){
System.out.print("并用手机播放了《一路上有你》的歌曲。");
}
public void takephoto(){
System.out.println("手机自拍了一张巡回演唱会的照片,");
}
}//Person类
public class Person {
public void use(Dailup D){
D.dailup();
}
public void use(Play P){
P.play();
}
public void use(Takephoto T){
T.takephoto();
}
}//Test测试
public class Test {
public static void main(String[] args) {
Person person=new Person();
}
}我想问一下Test测试类要怎么继续写下去?? 顺便帮我看一下我的代码有没有写的不对的!!!
习惯受伤
相关分类