使用java线程监控设备压力和热量值的小作业

zhlei1012 2017-11-08 07:54:53
1.下面是英文作业要求:
Write a class Controller (extends Thread) that can poll the sensors concurrently to running the device. You should implement its run() method such that it starts the device and then monitors it by waiting for and examining any new sensor values. The controller shuts down the device if the heat sensor exceeds the value 70 or the pressure sensor the value 100. Also complete the run() method in the class Sensor which calls updateValue() continuously and signals the controller if its value has changed. You can print the heat and pressure value to console in the run() method of Controller to check
2.下面是自己翻译的内容,不一定准确,大神们可以再看看:
编写一个类控制器(扩展线程),可以同时轮询传感器运行设备。 您应该实现其run()方法,以便启动设备,然后通过等待和检查任何新的传感器值来监视它。 如果热传感器的值超过70,或者压力传感器的值为100,控制器将关闭设备。同样,在类Sensor中调用updateValue()的方法完成run()方法,并在控制器的值发生变化时通知控制器。 您可以在Controller的run()方法中打印热量和压力值以进行检查。
3.main方法中给的实例化的代码:
public static void main(String[] args) {

Device device = new Device();
Sensor heat = new Sensor(device);
Sensor pressure = new Sensor(device);

Controller controller = new Controller(device,heat,pressure);

controller.start();
heat.start();
pressure.start();
}
4.下面是输出结果:
Device started
heat -> 0.00 , pressure -> 0.00
heat -> 0.80 , pressure -> 2.10
heat -> 15.50 , pressure -> 15.40
heat -> 30.30 , pressure -> 31.10
heat -> 66.40 , pressure -> 68.90
heat -> 68.70 , pressure -> 132.60
Device shutting down due to maintenance

要求完成线程类的代码!!
...全文
69 回复 点赞 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Java SE
加入

6.2w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2017-11-08 07:54
社区公告
暂无公告