有挑战的一道试题
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
兄弟不明白这三个参数有什么用。我觉得起一个线程产生double随机数不就行了嘛。望高人指点。谢谢了
[解决办法]
随机数肯定不行。别人都说了,data是一直增长的,随机数无法保证这个需求。
起个thread,每隔一定的时间给double的sum值累加。累加上去的值是随机的。
时间间隔也可以是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(所以我用静态变量),主要的是传数据的过程,这个过程是个线程。
本题就是让你写一个服务器端(有个变量不断增加),然后写一个客户端(接受这个增量,然后打印出来)。
现在你要做的是吧这个过程写成算法,和实际问题没什么关系吧,是让你把众多实际问题抽象出来些出算法。
[解决办法]