有挑战的一道试题 A customer has a system that captures data from a serial stream supplying data from a conveyor belt machine. This conveyor machine has its own hardware module to calculate its weight accumulated over time. It is a total weight reading (in lbs) that is sent out continuously on a serial port. The weight cannot be reset on the machine and will continuously increase as the conveyor operates. The client is going to build a component that reads this serial data and passes the same data to a new application for display purposes.
You will have to build a data simulator in your application that simulates the data that will be sent to you. It will have the following parameters passed in: ? Timestamp of the data ? Current total weight value as a double ? Status message as a string to indicate the equipment state
时间间隔也可以是random的
------解决方案-------------------- ? Timestamp of the data //时间标签是必须有的,“calculate its weight accumulated over time”因为需要随着时间的增加计算weight。 ? Current total weight value as a double//“The client is going to build a component that reads this serial data and passes the same data to a new application for display purposes.”知道现在的weight,client才能读取它,并且传递它。 ? Status message as a string to indicate the equipment state//线程必须有的状态信息,状态有等待,终止,运行,睡眠,唤醒。
------解决方案-------------------- 不用上面的3个参数貌似不行吧,题目要求的应该不能少,其实这不就是个很简单的线程问题吗,不用搞的那么复杂吧。。。。 一个是产生data,一个是接受和打印data,你再仔细看看英文,不要把问题想的太复杂,建个uml理解下,把名词都看成对象就行了,根据对象建类。 你再仔细想想,实在不会我再给你写代码。
------解决方案--------------------
一直增长的问题我觉得只要不停的把产生的随机数求和就行了。和random函数没什么关系吧!!题目只是让你记数,你只需要设置个计数值就行了,把它定义为static的静态变量不就行了。这个也不是考你具体功能,更像是uml建模的题,你只要把题目给你的功能用编程语言描述就行,不需要具体实现。写的是算法。
------解决方案-------------------- 这个题的关键不是传数啊,你用random和你传1(每次我都输入一个数进去就行,用Scanner函数获得键盘上的数值,当然我没有说你的random错,我只是想说用不找那么复杂)没什么区别,关键是这个数不能reset(所以我用静态变量),主要的是传数据的过程,这个过程是个线程。
------解决方案-------------------- 我认为三个参数的意义是: ? Timestamp of the data 时间戳,用来计算累加的重量 ? Current total weight value as a double 当前重量 ? Status message as a string to indicate the equipment state 状态标识