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随机数不就行了嘛。望高人指点。谢谢了

解决方案 »

  1.   

    随机数肯定不行。别人都说了,data是一直增长的,随机数无法保证这个需求。
    起个thread,每隔一定的时间给double的sum值累加。累加上去的值是随机的。时间间隔也可以是random的
      

  2.   

    • 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.   


    continuously increase as the conveyor operates    data是一直增长的
      

  4.   

    public class DataSimulator implements Runnable{
    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);

    }
    }各位兄弟说说我的这个方案怎么样? 但是我不能用那三个所要求参数。给点意见吧。
      

  5.   

    不用上面的3个参数貌似不行吧,题目要求的应该不能少,其实这不就是个很简单的线程问题吗,不用搞的那么复杂吧。
    一个是产生data,一个是接受和打印data,你再仔细看看英文,不要把问题想的太复杂,建个uml理解下,把名词都看成对象就行了,根据对象建类。
    你再仔细想想,实在不会我再给你写代码。
      

  6.   

    我觉得那三个参数是不是要由数据产生器传给显示界面的。这样的话我可以计算:
    1. 每一次reset后的总重量。
    2. 迄今为止移动的lbs/second.一直增长的问题我觉得只要不停的把产生的随机数求和就行了。
      

  7.   


    这位兄弟的话有道理,我想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。目前就这麽简单。其他的请指导。
      

  8.   

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

  9.   


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

  10.   

    “题目只是让你记数,你只需要设置个计数值就行了,把它定义为static的静态变量不就行了”这样会不会破坏数据的封装性?
      

  11.   

    这个题的关键不是传数啊,你用random和你传1(每次我都输入一个数进去就行,用Scanner函数获得键盘上的数值,当然我没有说你的random错,我只是想说用不找那么复杂)没什么区别,关键是这个数不能reset(所以我用静态变量),主要的是传数据的过程,这个过程是个线程。本题就是让你写一个服务器端(有个变量不断增加),然后写一个客户端(接受这个增量,然后打印出来)。
    现在你要做的是吧这个过程写成算法,和实际问题没什么关系吧,是让你把众多实际问题抽象出来些出算法。
      

  12.   

    这相当于一个生动、严格的系统模拟设计,除了核心参数累计的重量外,其它参数的合理设计是为了更稳定、完善化这个系统~我的理解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比如第一个参数,数据的timestamp,某些业务逻辑的应用中会用到这个时间戳,因为需要知道哪个重量阶段是生成于哪个时间阶段第三个参数,设备状态信息,设备是否运转完好,稳定,当前状态值如何等可能会对某些延伸应用具参考意义
      

  13.   


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

  14.   

    我认为三个参数的意义是:
    • Timestamp of the data 时间戳,用来计算累加的重量
    • Current total weight value as a double  当前重量
    • Status message as a string to indicate the equipment state  状态标识而要显示的重量为当前重量加上增量。增量的计算就与时间有关系了,我觉得应该用一个变量保存上次的时间戳,两次时间戳之差再乘以一个参数即可作为增量。如果是第一次传递,即上次时间戳为0,则增量为0.第三个参数姑且用来显示用吧,或者作为一个线程结束的标志。
      

  15.   

    为什么youcongwang的回复被删?
      

  16.   

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