由上图类图中可以看出,我们需要3个接口,2个实现类,以及1个
抽象类大致的案例创建如下图所示:
//连接网络接口
package dao;
public interface Network {
public void netWorkConn();
}
播放音频接口:
package dao;
public interface PlayWiring {
public void play(String content);
}
//拍照实现接口:
package dao;
public interface TheakePictures {
public void takePictures();
}
package entity;
public abstract class Handset {
private String brand;
private String type;
//构造方法
//无参方法
public Handset() {}
//带参方法
public Handset(String brand,String type) {
this.brand=brand;
this.type=type;
}
//手机的自白
public void info() {
System.out.println("这是一款型号为"+type+"的"+brand+"手机~~~");
}
//发送信息
public void sendInfo() {
System.out.println("发送文字信息~~~");
}
//打电话
public void call() {
System.out.println("正在打电话~~~");
}
}
<
package impl;
import dao.Network;
import dao.PlayWiring;
import dao.TheakePictures;
import entity.Handset;
public class AptitudeHandset extends Handset implements Network,PlayWiring,TheakePictures{
//构造方法
public AptitudeHandset() {}
public AptitudeHandset(String brand,String type) {
super(brand, type);
}
@Override
public void takePictures() {
System.out.println("咔嚓。。。拍照成功~~~");
}
@Override
public void play(String content) {
System.out.println("正在播放视频《"+content+"》~~~~");
}
@Override
public void netWorkConn() {
System.out.println("已经启动移动网络~~~");
}
@Override
public void sendInfo() {
System.out.println("正在发送带图片与文字的信息~~~");
}
@Override
public void call() {
System.out.println("开始视频通话~~~");
}
}
/>
<
package impl;
import dao.PlayWiring;
import entity.Handset;
public class CommonHandset extends Handset implements PlayWiring{
public CommonHandset(String brand,String type) {
super(brand, type);
}
@Override
public void play(String content) {
System.out.println("正在播放音乐《"+content+"》~~~");
}
@Override
public void sendInfo() {
System.out.println("发送文字信息~~~");
}
@Override
public void call() {
System.out.println("开始语音通话~~~");
}
}
/>
<
package test;
import impl.AptitudeHandset;
import impl.CommonHandset;
public class testTel {
public static void main(String[] args) {
CommonHandset comm=new CommonHandset("索尼爱立信", "G502c");
comm.info();
comm.play("热血");
comm.sendInfo();
comm.call();
System.out.println();
AptitudeHandset apt=new AptitudeHandset("I9100", "HTC");
apt.info();
apt.netWorkConn();
apt.play("小时代");
apt.takePictures();
apt.sendInfo();
apt.call();
}
}
/>
至此,全部功能已实现,圆满完成,如果有更好的方法,欢迎和小星星评论探讨哇~~~