日期:2014-05-20  浏览次数:20735 次

有挑战的一道试题
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(所以我用静态变量),主要的是传数据的过程,这个过程是个线程。

本题就是让你写一个服务器端(有个变量不断增加),然后写一个客户端(接受这个增量,然后打印出来)。
现在你要做的是吧这个过程写成算法,和实际问题没什么关系吧,是让你把众多实际问题抽象出来些出算法。
------解决方案--------------------
探讨

引用:

我们想象超市的收银台,传过来的物品重量是不一样的,这就是我为什么要用random函数。我目前搞不懂为什么要那三个参数。

------解决方案--------------------
我认为三个参数的意义是:
? Timestamp of the data 时间戳,用来计算累加的重量
? Current total weight value as a double 当前重量
? Status message as a string to indicate the equipment state 状态标识

而要显示的重量为当前重量加上增量。增量的计算就与时间有关系了,我觉得应该用一个变量保存上次的时间戳,两次时间戳之差再乘以一个参数即可作为增量。如果是第一次传递,即上次时间戳为0,则增量为0.第三个参数姑且用来显示用吧,或者作为一个线程结束的标志。
------解决方案--------------------
探讨

能说的具体点吗?我用random生成一个随机的放置到传送带上的物品重量,比如random(System.currentTimeMillSeconds);那么这个时间戳是不是就是System.currentTimeMillSeconds这个值?

------解决方案--------------------
一直增长的问题我觉得只要不停的把产生的随机数求和就行了。和random函数没什么关系吧!!题目只是让你记数,你只需要设置个计数值就行了,把它定义为static的静态变量不就行了。这个也不是考你具体功能,更像是uml建模的题,你只要把题目给你的功能用编程语言描述就行,不需要具体实现。写的是算法。
------解决方案--------------------
看了下,我觉得这个和流媒体很相视

首先应该是有一个读取数据线程,一直从某个端口接收数据,可以有一个缓冲区,也可以没有
然后有一个显示线程,根据硬件的提供的定时器按固定速率显示数据。

时间戳的作用是用来标示数据的发送顺序和时间,方便接收的时候计算顺序和时间
当前重量肯定是要的
第三个参数设备状态也是有用的,肯能机器暂停发送数据或者机器出了问题,可以用状态来标示