Java程序开发一个应用,模拟计算机对移动存储设备的读写,即移动存储设备有U盘手机卡移动硬盘闪卡等设备
目录
Java程序:开发一个应用,模拟计算机对移动存储设备的读写,即移动存储设备有U盘、手机卡、移动硬盘、闪卡等设备
开发一个应用,模拟计算机对移动存储设备的读写,即移动存储设备有U盘、手机卡、移动硬盘、闪卡等设备
public interface Mobile {
void Read();
void Write();
}
public class Upan implements Mobile{
public void Read() {
System.out.println("读取U盘");
}
public void Write() {
System.out.println("识别U盘中的信息写入");
}
}
public class Sjk implements Mobile{
public void Read() {
System.out.println("读入手机卡信息");
}
public void Write() {
System.out.println("运行手机卡信息");
}
}
public class Ydyp implements Mobile{
public void Read() {
System.out.println("读入硬盘信息");
}
public void Write() {
System.out.println("运行硬盘信息");
}
}
public class Sk implements Mobile{
public void Read() {
System.out.println("读入闪卡信息");
}
public void Write() {
System.out.println("运行闪卡信息");
}
}
public class Computer {
Mobile sebei;
public void setUserDriver(Mobile sebei){
this.sebei = sebei;
}
public Computer(){
}
public Computer(Mobile sebei){
this.sebei = sebei;
}
public void ReadData(){
this.sebei.Read();
}
public void WriteData(){
this.sebei.Write();
}
}
public class Main {
public static void main(String[] args) {
Computer computer = new Computer();
Mobile Sjk = new Sjk ();
Mobile Upan = new Upan ();
Mobile Ydyp = new Ydyp ();
Mobile Sk = new Sk ();
System.out.println("接入u盘");
computer.sebei =Upan;
computer.ReadData();
computer.WriteData();
System.out.println();
System.out.println("接入手机卡");
computer.sebei = Sjk;
computer.ReadData();
computer.WriteData();
System.out.println();
System.out.println("接入移动硬盘");
computer.sebei=Ydyp;
computer.ReadData();
computer.WriteData();
System.out.println();
System.out.println("接入闪卡");
computer.sebei = Sk;
computer.ReadData();
computer.WriteData();
}
}
答
: