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随机数不就行了嘛。望高人指点。谢谢了
• Timestamp of the data
• Current total weight value as a double
• Status message as a string to indicate the equipment state兄弟不明白这三个参数有什么用。我觉得起一个线程产生double随机数不就行了嘛。望高人指点。谢谢了
起个thread,每隔一定的时间给double的sum值累加。累加上去的值是随机的。时间间隔也可以是random的
• 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//线程必须有的状态信息,状态有等待,终止,运行,睡眠,唤醒。
continuously increase as the conveyor operates data是一直增长的
private long timeStamp = 0;
private double currentTotalWeight = 0.0;
private String status = null;
private Random random = null;
private int seed = 0;
private double item = 0;
private int sleepSecs = 0;
public void run() {
random = new Random(timeStamp);
seed = random.nextInt();
item = (Math.abs(seed % 100) + 1);
long count = 10;//00000;
sleepSecs = (int) Math.abs(seed % 60 + 1);
// double sum = 0;
for(int i = 0; i < count; i++)
// while(resetFlag)
{
random = new Random(System.currentTimeMillis());
// Random random2 = new Random(System.currentTimeMillis());
seed = random.nextInt();
// int seed2 = random.nextInt();
item = (Math.abs(seed % 100) + 1);
sleepSecs = Math.abs(seed % 5000 + 1);
currentTotalWeight += item;
System.out.println("loop: " + i + "\t seed :" + seed +
"\tweight of item : " + item +
"\tsum of the item:" + currentTotalWeight +
"\tsleep time is:" + sleepSecs);
try {
Thread.sleep(sleepSecs);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// System.out.println("weight of item : " + item);
System.out.println("sum of the item:" + currentTotalWeight);
}
}各位兄弟说说我的这个方案怎么样? 但是我不能用那三个所要求参数。给点意见吧。
一个是产生data,一个是接受和打印data,你再仔细看看英文,不要把问题想的太复杂,建个uml理解下,把名词都看成对象就行了,根据对象建类。
你再仔细想想,实在不会我再给你写代码。
1. 每一次reset后的总重量。
2. 迄今为止移动的lbs/second.一直增长的问题我觉得只要不停的把产生的随机数求和就行了。
这位兄弟的话有道理,我想data做一个类,包括
• Timestamp of the data
• Current total weight value as a double
• Status message as a string to indicate the equipment state
这三个属性;simulator做一个类,这后一类主要模拟serial port。目前就这麽简单。其他的请指导。
有水平。我们想象超市的收银台,传过来的物品重量是不一样的,这就是我为什么要用random函数。我目前搞不懂为什么要那三个参数。
现在你要做的是吧这个过程写成算法,和实际问题没什么关系吧,是让你把众多实际问题抽象出来些出算法。
• Timestamp of the data
• Current total weight value as a double
• Status message as a string to indicate the equipment state比如第一个参数,数据的timestamp,某些业务逻辑的应用中会用到这个时间戳,因为需要知道哪个重量阶段是生成于哪个时间阶段第三个参数,设备状态信息,设备是否运转完好,稳定,当前状态值如何等可能会对某些延伸应用具参考意义
能说的具体点吗?我用random生成一个随机的放置到传送带上的物品重量,比如random(System.currentTimeMillSeconds);那么这个时间戳是不是就是System.currentTimeMillSeconds这个值?
• Timestamp of the data 时间戳,用来计算累加的重量
• Current total weight value as a double 当前重量
• Status message as a string to indicate the equipment state 状态标识而要显示的重量为当前重量加上增量。增量的计算就与时间有关系了,我觉得应该用一个变量保存上次的时间戳,两次时间戳之差再乘以一个参数即可作为增量。如果是第一次传递,即上次时间戳为0,则增量为0.第三个参数姑且用来显示用吧,或者作为一个线程结束的标志。