【0718作业】接口实现手机
作者:互联网
【接口】
1 package com.mobile; 2 /** 3 * - 连接网络接口 4 * @author L 5 * 6 */ 7 public interface Network { 8 public abstract void network(); 9 }
1 package com.mobile; 2 /** 3 * - 播放视频接口 4 * @author L 5 * 6 */ 7 public interface PlayWiring { 8 public abstract void playvideo(); 9 }
1 package com.mobile; 2 /** 3 * - 照相接口 4 * @author L 5 * 6 */ 7 public interface TheakePictures { 8 public abstract void picture() ; 9 }
【手机类】
1 package com.mobile; 2 /** 3 * - 手机类 4 * @author L 5 * 6 */ 7 public abstract class Handset { 8 9 private String brand;//品牌 10 private String type;//类型 11 12 13 public String getBrand() { 14 return brand; 15 } 16 public void setBrand(String brand) { 17 this.brand = brand; 18 } 19 public String getType() { 20 return type; 21 } 22 public void setType(String type) { 23 this.type = type; 24 } 25 26 public void call() { 27 System.out.println("支持通电话"); 28 29 } 30 public void message() { 31 System.out.println("支持发短信"); 32 } 33 34 public abstract void showInfo(); 35 36 37 }
【普通手机】
1 package com.mobile; 2 /** 3 * 普通手机 4 * @author L 5 * 6 */ 7 public class CommonHandset extends Handset implements PlayWiring{ 8 9 @Override 10 public void playvideo() { 11 // TODO Auto-generated method stub 12 System.out.println("支持播放音频"); 13 } 14 15 @Override 16 public void showInfo() { 17 // TODO Auto-generated method stub 18 System.out.println("一台"+this.getBrand()+this.getType()+"的手机"); 19 } 20 21 }
【智能手机】
1 package com.mobile; 2 /** 3 * - 智能手机 4 * @author L 5 * 6 */ 7 public class AptitudeHandset extends Handset implements Network,PlayWiring,TheakePictures{ 8 9 @Override 10 public void picture() { 11 // TODO Auto-generated method stub 12 System.out.println("支持拍照功能"); 13 14 } 15 16 @Override 17 public void playvideo() { 18 // TODO Auto-generated method stub 19 System.out.println("支持播放视频"); 20 } 21 22 @Override 23 public void network() { 24 // TODO Auto-generated method stub 25 System.out.println("支持4G网络"); 26 } 27 28 @Override 29 public void showInfo() { 30 // TODO Auto-generated method stub 31 System.out.println("一台"+this.getBrand()+this.getType()+"的手机"); 32 } 33 34 35 36 }
【测试】
1 package com.mobile; 2 /** 3 * - 测试类 4 * - 实现普通手机和智能手机 5 * @author L 6 * 7 */ 8 public class Test { 9 public static void main(String[] args) { 10 11 //普通手机功能 12 //包含播放音频、发短信、通电话 13 CommonHandset commonhandset= new CommonHandset(); 14 commonhandset.setBrand("摩托罗拉"); 15 commonhandset.setType("盗版直板机"); 16 commonhandset.showInfo(); 17 commonhandset.message(); 18 commonhandset.call(); 19 commonhandset.playvideo(); 20 System.out.println(); 21 22 23 //智能手机功能 24 //包含上网、播放视频、照相、发短信、通电话 25 AptitudeHandset aptitudehandset=new AptitudeHandset(); 26 aptitudehandset.setBrand("华为"); 27 aptitudehandset.setType("P30"); 28 aptitudehandset.showInfo(); 29 aptitudehandset.network(); 30 aptitudehandset.playvideo(); 31 aptitudehandset.picture(); 32 aptitudehandset.message(); 33 aptitudehandset.call(); 34 System.out.println(); 35 36 } 37 }
【结果】
标签:aptitudehandset,void,作业,System,接口,0718,println,public,out 来源: https://www.cnblogs.com/yanglanlan/p/11222939.html