Tuesday, 16 September 2014

Get the average from xml list



I have a list (USAGE_LIST) of data that contains some fields year and month and usage, i would like to get the average of the last 3 months of the usage field, I tried something like Calendar.getInstance() with SimpleDateFormat and getTime() but becuase i dont have really date, it doest work, what is the best way to do that, please an example. thanks and thanks for StackoverFlow



<USAGE_LIST>
<TOTAL>
<YEAR>2013</YEAR>
<MONTH>10</MONTH>
<USAGE>200</USAGE>
</TOTAL>
<TOTAL>
<YEAR>2013</YEAR>
<MONTH>11</MONTH>
<USAGE>250</USAGE>
</TOTAL>
<TOTAL>
<YEAR>2013</YEAR>
<MONTH>12</MONTH>
<USAGE>500</USAGE>
</TOTAL>
<TOTAL>
<YEAR>2014</YEAR>
<MONTH>1</MONTH>
<USAGE>300</USAGE>
</TOTAL>
</USAGE_LIST>

No comments:

Post a Comment