接口实现手机功能

news/2024/10/19 21:36:20/

1. 实现思路
2. 编写类及接口
3. 编写测试类、让手机播放音频、发信息和通电话
4. 让智能手机上网、播放视频、照相、发信息和通电话

TheakePictures接口
//照相public interface TheakePictures {void takePictures();}``
NetWork接口
//连接网络
public interface NetWork {void netWorkConn();
}
PlayWiring 接口
//播放
public interface PlayWiring {void play();
/*** 手机抽象类*/
public abstract  class Handset {private  String brand;private  String type;public abstract void sendInfo();public abstract void call();public abstract void info();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 abstract void show();
}
/*** 智能手机类*/
public class AptitudeHandset extends Handset implements NetWork,TheakePictures,PlayWiring{@Overridepublic void sendInfo() {System.out.println(this.getBrand()+this.getType()+"发信息");}@Overridepublic void call() {System.out.println(this.getBrand()+this.getType()+"打电话");}@Overridepublic void info() {System.out.println(this.getBrand()+this.getType()+"收信息");}@Overridepublic void netWorkConn() {System.out.println(this.getBrand()+this.getType()+"上网");}@Overridepublic void play() {System.out.println(this.getBrand()+this.getType()+"播放视频");}@Overridepublic void takePictures() {System.out.println(this.getBrand()+this.getType()+"照照片");}public void show(){this.netWorkConn();this.call();this.sendInfo();this.takePictures();this.play();}
}
/*** 普通手机类*/
public class CommonHandset extends Handset implements PlayWiring {@Overridepublic void sendInfo() {System.out.println(this.getBrand()+this.getType()+"手机发信息");}@Overridepublic void call() {System.out.println(this.getBrand()+this.getType()+"手机打电话");}@Overridepublic void info() {System.out.println(this.getBrand()+this.getType()+"手机收信息");}@Overridepublic void play() {System.out.println(this.getBrand()+this.getType()+"手机播放视频");}@Overridepublic void show() {this.call();this.sendInfo();this.play();}
}
import java.util.Scanner;/*** 装配手机类*/
public class Host {Scanner sc=new Scanner(System.in);int brandId,typeId;//手机品牌 手机型号public Handset select(int type){Handset handset;if(type==1){/*** 实现智能手机功能*/handset=new AptitudeHandset();System.out.println("1、小米 2、华为、 3、苹果");System.out.println("请选择手机品牌:");brandId=sc.nextInt();switch (brandId){case 1://设置手机品牌handset.setBrand("小米");// System.out.println(aptitudeHandset.getBrand());System.out.println("1、红米 2、小米note 3、小米8");System.out.println("请选择小米手机类型");typeId=sc.nextInt();//设置小米手机类型if(typeId==1){handset.setType("红米");}else if (typeId==2){handset.setType("小米note");}else {handset.setType("小米8");}break;case 2:handset.setBrand("华为");System.out.println("1、荣耀  2、nava  3、华为10");System.out.println("请选择华为手机类型");typeId=sc.nextInt();//设置小米手机类型if(typeId==1){handset.setType("荣耀 ");}else if (typeId==2){handset.setType("nava");}else {handset.setType("华为10");}break;default:handset.setBrand("苹果");System.out.println("1、iphone7  2、iphoneX  3、iphone9");System.out.println("请选择华为手机类型");typeId=sc.nextInt();//设置小米手机类型if(typeId==1){handset.setType("iphone7 ");}else if (typeId==2){handset.setType("iphoneX");}else {handset.setType("iphone9");}break;}}else{/*** 实现普通手机功能*/handset=new CommonHandset();System.out.println("1、诺基亚 2、金立手机 3、三星");System.out.println("请选择普通手机品牌");brandId=sc.nextInt();switch (brandId){case 1://设置手机品牌handset.setBrand("诺基亚");System.out.println("1、210黑色直板 2、105老人备用机 3、3.1plus移动版");System.out.println("请选择诺基亚手机类型");typeId=sc.nextInt();if (typeId==1){handset.setType("210黑色直板");}else if(typeId==2){handset.setType("105老人备用机");}else {handset.setType("3.1plus移动版");}break;case 2:handset.setBrand("金立");System.out.println("1、语音王 2、A350");System.out.println("请选择金立手机类型");typeId=sc.nextInt();if(typeId==1){handset.setType("语音王");}else {handset.setType("A350");}break;default:handset.setBrand("三星");System.out.println("1、B289电信 2、E1150老人机");System.out.println("请选择三星手机类型");typeId=sc.nextInt();if(typeId==1){handset.setType("B289电信");}else {handset.setType("E1150老人机");}break;}}return  handset;}
}
import java.util.Scanner;/*** 测试类*/
public class Test {public static void main(String[] args) {Scanner sc=new Scanner(System.in);Host host=new Host();
//        AptitudeHandset aptitudeHandset=new AptitudeHandset();
//        CommonHandset commonHandset=new CommonHandset();Handset handset;System.out.println("1、智能手机 2、普通手机");System.out.println("请选择手机类型:");int chiooce=sc.nextInt();handset=host.select(chiooce);handset.show();}
}

http://www.ppmy.cn/news/625999.html

相关文章

Conda 命令深入指南

Conda 命令深入指南 Conda 是一个功能强大的包管理系统,允许您为不同的项目创建和管理隔离的环境,从而更轻松地处理不同的依赖项集。 安装 可以按照 Conda 官方网站 (https://conda.io) 上提供的说明下载并安装 Conda。 安装后,可以打开终…

卷积神经网络的三大特性

卷积神经网络(CNN)的三大特性是: Sparse Interaction(稀疏交互):稀疏交互是指在卷积神经网络中,每个神经元仅与输入数据的局部区域进行交互。这意味着神经元只对输入数据的一小部分感知&#xf…

linux查看服务器光模块功率命令

描述:linux查看服务器光模块功率命令 步骤: 使用root用户执行下面命令 ip a s #查看网卡名称 ethtool -m 网卡名称 #查看网卡信息

基于STM32F1的自动追光云台(代码开源)

前一段时间做了一个自动追光云台(大家感兴趣的也可以自己DIY一个呀),用来自动捕捉阳光供太阳板发电提高太阳板的发电效率,我用了一款STM32f103c8t6为主控来控制云台舵机的旋转。感光元器件使用的是光敏传感器(淘宝随便…

OpenGL入门教程

概述 OpenGL OpenGL是渲染2D、3D矢量图形硬件的一种软件接口。本质上说,它是一个3D图形和模型库,具有高度的可移植性,并且具有非常快的渲染速度。OpenGL并不是一种语言,而是更像一个C运行时函数库。它提供了一些预包装的功能&am…

echart 绘制一个基础的中国地图

echart&#xff0c;绘制一个基础的中国地图 代码示例 <template><div id"china_map_box"><div id"china_map"></div></div> </template><script> import * as echarts from echarts import chinaJson from ./…

从零开始用树莓派做一个社交距离检测仪(树莓派4B+摄像头推流教程)持续更新

最近&#xff0c;内蒙古地区的疫情越来越严重了&#xff0c;我们本地也开始了全体核酸检测&#xff0c;在排队的过程中&#xff0c;往往会有排队距离太近的情况发生。我有很多做志愿者的朋友&#xff0c;大家在聊天的时候也会时常提到这个问题。因此&#xff0c;我决定使用树莓…

基于树莓派的追光系统(python)

目录 前言 一、材料 二、硬件--控制逻辑 1.主设备的准备 1.启用树莓派的i2c设备 2.安装python-smbus 2.从设备的准备 1.BH1750 2.L298N驱动芯片 3.云台的准备 1.增加电机固定模块 2.增加bh1750固定模块 三、软件--程序逻辑 1.总程序逻辑 2.光强检测程序逻辑 3.…