A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 小穿钉 高级黑马   /  2015-10-14 09:06  /  858 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


//设计一个USB接口。USB设备电压为5V,实现数据read()和写数据write()操作。
public interface USB{
       //USB设备电压5V
        public static final int V=5;

        //读取数据,存放在byte[]数据中
        public abstract byte[] read();

       //写入数据,数据源是byte[]数据
        public abstract void write (byte[] data);
}

//定义Computer类,通过implenents关键字实现USB接口
public class Computer implenents USB{
       //内存空间
        int memorySize;
       //USB接口方法,读数据
        public byte[] read(){
                byte[] buffer=new byte[256];
                //读取USN设备数据,存放在buffer中
                System.out.println("读书USB设备数据");
                //读数据的一系列操作
                return buffer;
        }
        //USB接口方法,写数据
        public void write(byte[] data){
                //读取USB设备数据
                System.out.println("向USB设备写入数据");
                //写数据的一系列操作
        }
}

//媒体播放器设备类,实现USB接口
public class Player implenenets USB{
        //存储空间
        int memorySize;
        //USB接口方法,读数据
        public byte[] read(){
                byte[] buffer=new byte[256];
                System.out.println("读取播放器设备数据");
                //读数据的一系列操作
                return buffer;
        }
       //USB接口方法,写数据
        public void write(byte[] data){
                System.out.println("向播放器设备写入数据");
                //写数据的一系列操作
        }
}

//测试主类
public class USBTest{
        public static void main(String[] args){
                System.out.println("Computer实现USB接口");
                Computer c=new Computer();
                System.out.println(Computer.V);
                c.read();
                c.write(null);
                System.out.println("Player实现USB接口");
                Player p=new Player();
                Syste.out.println(Player.V);
                p.read();
                p.write(null);
        }
}

终于码完了

6 个回复

倒序浏览
谢谢大神分享
回复 使用道具 举报

哪有,需要向你学习,刚来的小白,求关照
回复 使用道具 举报
谢谢分享,学习下。
回复 使用道具 举报
赖洪光 发表于 2015-10-14 10:37
谢谢分享,学习下。

一起进步学习
回复 使用道具 举报
666666666666
回复 使用道具 举报

同学,共勉之。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马