[实验任务一]:计算机开启
在计算机主机(Mainframe)中,只需要按下主机的开机按钮(on()),即可调用其他硬件设备和软件的启动方法 ,如内存(Memory)的自检(check())、CPU的运行(run())、硬盘(HardDisk)的读取(read())、操作系统(OS)的载入(load()),如果某一过程发生错误则计算机启动失败。
1. 提交类图;
2. 提交源代码;
Client.java
package Facade;
public class Client {
public static void main(String args[]) {
MainFrame mf=new MainFrame();
System.out.println("电脑启动成功。。。");
mf.on();
System.out.println("电脑启动失败。。。");
mf.off();
}
}
CPU.java
package Facade;
public class CPU {
public void run() {
System.out.println("CPU正在运行");
}
public void off() {
System.out.println("CPU发生错误");
}
}
HardDisk.java
package Facade;
public class HardDisk {
public void read() {
System.out.println("硬盘正在读取");
}
public void off() {
System.out.println("硬盘发生错误");
}
}
MainFrame.java
package Facade;
public class MainFrame {
//维持对子系统对象的引用
private Memory memory;
private CPU cpu;
private OS os;
private HardDisk disk;
public MainFrame() {
memory=new Memory();
cpu=new CPU();
os=new OS();
disk=new HardDisk();
}
//调用子系统对象的业务方法
public void on() {
memory.check();
cpu.run();
os.load();
disk.read();
}
public void off() {
memory.off();
cpu.off();
os.off();
disk.off();
}
}
Memory.java
package Facade;
public class Memory {
public void check() {
System.out.println("内存正在自检");
}
public void off() {
System.out.println("内存发生错误");
}
}
OS.java
package Facade;
public class OS {
public void load() {
System.out.println("OS正在载入");
}
public void off() {
System.out.println("OS发生错误");
}
}
标签:外观,off,void,System,模式,println,public,out
From: https://www.cnblogs.com/yzx-sir/p/17851828.html