需求说明:原始的手机,可以发短信,通电话。随着发展,手机增加了音频、视频播放、拍照、上网功能。按照作业3的思路和下面的类图进行程序设计:首先,编写类及接口,参照以下类的结构图;其次,编写测试类,让普通手机播放音频、发信息和通电话,让智能手机上网、播放视频、照相、发彩信和视频通电话。
//抽象手机类
public abstract class Handset {
private String brand;//手机品牌
private String type;//手机类型
//抽象方法
abstract void sendInfo();
abstract void call();
//show方法
public void show(){
System.out.println("这是一款型号为"+type+"的"+brand+"手机");
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
//普通手机类
public class CommonHandset extends Handset implements PlayWiring{
@Override
public void play(String content) {
System.out.println("开始播放音乐"+content+"......");
}
@Override
void sendInfo() {
System.out.println("发送文字信息......");
}
@Override
void call() {
System.out.println("开始语音通话......");
}
}
//智能手机类
public class AptitudeHandst extends Handset implements PlayWiring,Network,TheakePictures{
@Override
public void NetWorkConn() {
System.out.println(“已经启动移动网络”);
}
@Override
public void play(String video) {
System.out.println("开始播放视频"+video);
}
@Override
public void taskpicture() {
System.out.println("咔嚓。。。。。照相成功!");
}
@Override
void sendInfo() {
System.out.println("发送带图片与文字的信息......");
}
@Override
void call() {
System.out.println("开始视频通话");
}
}
//测试类
public class TestHandset {
public static void main(String[] args) {
//普通手机
CommonHandset c = new CommonHandset();
c.setBrand(“G502c”);
c.setType(“索尼爱立信”);
c.show();
c.play("《热雪》");
c.sendInfo();
c.call();
//智能手机
AptitudeHandst ah = new AptitudeHandst();
ah.setBrand("HTC");
ah.setType("I9100");
ah.show();
ah.NetWorkConn();
ah.play("《小时代》");
ah.taskpicture();
ah.sendInfo();
ah.call();
}
}
//网络接口
public interface Network {
void NetWorkConn();
}
//播放接口
package com.homework2.one;
public interface PlayWiring {
void play(String content);
}
//照相接口
public interface TheakePictures {
void taskpicture();
}