Results 1 to 3 of 3
  1. #1
    danborgir is offline Member
    Join Date
    Jan 2011
    Posts
    26
    Rep Power
    0

    Default Need help with creating average from vector

    Hi guys, I'm new here so please don't bite! :o

    I am developing a Network delay monitoring tool for my degree coursework, it works basically like a ping between two systems.

    The actual processing of the delay is finished, I used:

    Java Code:
    System.currentTimeMillis();
    to acquire the system time in ms after transmission and again when the message is received back. I then subtracted the first from the second t1 - t0 to get a delay time :)

    I now want to implement an average function so the user can see the average delay time. To do this I am using a Vector. The problem is I cannot add a long variable to the Vector; or I do not know how to!

    My code for working the vector is as follows:

    Java Code:
    Vector<String> v = new Vector<String>(); 
    
    v.add(ans) // this ans is the delay time long variable I want to add.
    
    for(int i = 0; i < v.size(); i++) {
    	sum = sum + Integer.parseInt(v.get(i));
    System.out.println("sum = " + sum);
    }
    when I compile I get the error:

    "client.java:80: cannot find symbol symbol : method add(long)
    location: class java.util.Vector<java.lang.String> v.add(ans);"

    I am really puzzled as what to do next so any help would really be appreciated!

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    :confused:

    1) Why do you write Vector<String> ? You dont want to store String objects, you want to store Long objects or? So you have to write List<Long> v = new Vector<Long>();

    2) Why do you want to parse it to Integer? You mean Long.parseLong ? But if you change your code as I said in 1) you dont have to parse! v.get(i) = Long :)

  3. #3
    danborgir is offline Member
    Join Date
    Jan 2011
    Posts
    26
    Rep Power
    0

    Default Thankyou!

    Thank you so much! I was using an online example and didn't really think about the parseInt, I really appreciate this it works perfectly now!! :D :D

Similar Threads

  1. Need help to find average
    By kevinsoto in forum New To Java
    Replies: 4
    Last Post: 11-04-2010, 01:54 PM
  2. average
    By anjigadu in forum New To Java
    Replies: 4
    Last Post: 09-19-2010, 09:52 PM
  3. Need help getting average
    By soccer_kid_6 in forum New To Java
    Replies: 15
    Last Post: 09-12-2010, 11:59 PM
  4. Calculating average
    By clocksaysits9 in forum New To Java
    Replies: 4
    Last Post: 04-06-2010, 05:03 AM
  5. Vector<vector> loop thru
    By ocean in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •