每日总结-23.11.20

发布时间 2023-11-20 09:19:59作者: lao_bing
public class Memory {

    private static Memory instance = new Memory();

    public static Memory getInstance() {
        return instance;

    }

    public boolean check(boolean operIf) {
        System.out.println("内存开始自检");
        if (operIf) {
            operIf = new java.util.Random().nextBoolean() ? true : false;
        }
        if (operIf) {
            System.out.println("内存自检完成");
            return true;
        } else {
            System.out.println("内存自检失败");
            return false;
        }

    }
}

public class CPU {

    private static CPU instance = new CPU();

    public static CPU getInstance() {
        return instance;

    }

    public boolean  run(boolean operIf) {
        System.out.println("cpu开始运行");
        if (operIf) {
            operIf =new java.util.Random().nextBoolean() ? true : false;
        }
        if (operIf) {
            System.out.println("cpu运行成功");
            return true;
        } else {
            System.out.println("cpu运行失败");
            return false;
        }
    }
}

public class HardDisk {

    private static HardDisk instance = new HardDisk();

    public static HardDisk getInstance() {
        return instance;

    }

    public boolean  read(boolean operIf) {
        System.out.println("硬盘开始读取");
        if (operIf) {
            operIf =new java.util.Random().nextBoolean() ? true : false;
        }
        if (operIf) {
            System.out.println("硬盘运行成功");
            return true;
        } else {
            System.out.println("硬盘运行失败");
            return false;
        }
    }
}

public class OS {

    private static OS instance = new OS();

    public static OS getInstance() {
        return instance;

    }

    public boolean  load(boolean operIf) {
        System.out.println("操作系统开始载入");
        if (operIf) {
            operIf =new java.util.Random().nextBoolean() ? true : false;
        }
        if (operIf) {
            System.out.println("操作系统载入成功");
            return true;
        } else {
            System.out.println("操作系统载入失败");
            return false;
        }
    }
}

public class Mainframe {

    private Memory memory;
    private CPU cpu;
    private HardDisk hardDisk;
    private OS os;
    private boolean operIf = true;

    public void setOperIf(boolean operIf) {
        this.operIf = operIf;
    }

    public Mainframe() {
        super();
        this.memory = memory.getInstance();
        this.cpu = cpu.getInstance();
        this.hardDisk = hardDisk.getInstance();
        this.os = os.getInstance();
    }

    public void on() {
        System.out.println("按下主机按钮");
        operIf=memory.check(operIf);
        operIf=cpu.run(operIf);
        operIf=hardDisk.read(operIf);
        operIf=os.load(operIf);
    }



}

public class Client {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Mainframe mainframe = new Mainframe();
        mainframe.on();

    }

}