title: do calculation inside JSONArray in Java
body: <p>I have a simple issue but cannot solve it as I am not very good at algorithm!
  I have an JSONArray in this form:</p>
  
  <pre><code>[{"values":[{"time":1434976493,"value":"50"},
  {"time":1434976494,"value":"100"}],"counter":"counter1"},
  
  {"values":[{"time":1434976493,"value":"200"},
  {"time":1434976494,"value":"300"}],"counter":"counter2"},
  
  {"values":[{"time":1434976493,"value":"400"},   
  {"time":1434976494,"value":"600"}],"counter":"total"}]
  </code></pre>
  
  <p>What I want to do is to get the integer value for counter 1 and counter 2 and then divide them by total counter and put them in a list or array. and of course I want total counter to be untouched! So the calculation would be <code>Counter1.value/total.value</code>, <code>Counter2.value/total.value</code> So for example the counter 1 would be like this:</p>
  
  <pre><code>{"values":[{"time":1434976493,"value":"50/400"},{"time":1434976494,"value":"100/600"}],"counter":"counter1"}
  </code></pre>
  
  <p>Thats an uncompleted attempt :</p>
  
  <p>(given that I have list of counters that I can iterate:)</p>
  
  <pre><code>int index= counters.indexOf("total");
  JSONObject rec = array.getJSONObject(index);
  </code></pre>
  
  <p>and then I got this for total counter: </p>
  
  <pre><code>{"values":[{"time":1434976493,"value":"400"},   
      {"time":1434976494,"value":"600"}]
  </code></pre>
  
  <p>not sure what is the next step?!</p>