• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to calculate average in this format ?  RSS feed

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
00:24:c3:31:2b:e0 -93
00:12:17:7b:33:04 -80
00:1f:27:55:f7:70 -70
00:1e:13:ee:3e:40 -85
00:24:c3:31:b8:80 -91
00:90:4c:60:04:02 -94
00:1b:0d:d6:6d:50 -70
00:1a:a2:dc:a0:60 -86
00:1e:c1:4c:c5:ce -94
00:24:c3:31:b8:80 -91
00:1e:c1:4c:c5:ce -94
00:1a:a2:dc:a0:60 -91


The above is part of my .txt file, is there any method to calculate the average value for each ID ?
The first part is ID, second is value.
(Note: There are repeated same ID, so how to get those value and calculate average ?

Maybe the result will be :
00:24:c3:31:2b:e0 average : -88
00:12:17:7b:33:04 average : -90
............
..........
 
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Read the txt file and store the IDs and values in a map so that, the ID-value pairs get stored as the key-value pair. Now while you fetch each ID do make sure that if the ID is present in the map add the value associated with the one is already present. After the file read operation, the calculation of averages shold not be a major issue, correct?

Cheers,
Raj.
 
motress zlting
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj Kamal wrote:Hi,

Read the txt file and store the IDs and values in a map so that, the ID-value pairs get stored as the key-value pair. Now while you fetch each ID do make sure that if the ID is present in the map add the value associated with the one is already present. After the file read operation, the calculation of averages shold not be a major issue, correct?

Cheers,
Raj.


ya,i have refer before about linkedhashmap. But i'm really new in Java programming and i need to complete it within one day. =="
Maybe for them is easy, but not for me.....
I'm very blur.....Any related hint ?
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What I'm talking about is:-

Loop:
A) Fetch token from file.
B) if it is alphanumeric
B.1) check if map contains this key.
B.1.a) if yes fetch next token and add to value already present in the map.
B.1.b) if no fetch next token and put the value for the key.
Continue Loop: if not end of file.
Stop

Does this answer your query?

Cheers,
Raj.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!