1 Replies - 1090 Views - Last Post: 02 August 2009 - 02:54 PM

#1 adrianjay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-August 09

How do I calculate the Average (Mean) for Interpreted Java?

Post icon  Posted 02 August 2009 - 01:06 PM

My knowledge of programming is very limited and I cant seem to figure the solution to my problem. I would like to calculate the average of session variables in Interpreted Java. However, some of session variables may not always be available.
The first thing I do is remove the non numerical portion of the session variables:

String [] variables = {"A ",B,C,D,E};

i = 0;

// Iterate through each variable in the array above
while (i < variables.length){

//Get the variables to be fixed
value = session.getVariable(variables[i]);

//Log the UNFIXED values
session.log("UNFIXED: " + variables[i] + " = " + value);

if(value != null){
//Remove non-numerical elements
value = value.replaceAll("\\D", "");

// Set variables with new values
dataRecord.put(variables[i], value);
session.setVariable(variables[i], value);

//Log the FIXED values
session.log("FIXED " + variables[i] + " = " + session.getVariable(variables[i]));
}
i++;
}



Then I make sure the session variables can be treated as numbers:

A = Integer.parseInt(session.getVariable("A")).intValue();
B = Integer.parseInt(session.getVariable("B")).intValue();
C = Integer.parseInt(session.getVariable("C")).intValue();
D = Integer.parseInt(session.getVariable("D")).intValue();
E = Integer.parseInt(session.getVariable("E")).intValue();

// Are they still alive?
session.log("A**" + A + "**");
session.log("B**" + B + "**");

session.log("C**" + C + "**");
session.log("D**" + D + "**");
session.log("E**" + E + "**");



I would like to calculate the average of A and B and save it as session variable AB, calculate the average of C and D and save it as session variable CD, and then the average of AB, CD, and E. Heres the weird part; AB, CD, and or E will not always be available. For example, AB will not be available so I need to calculate the average of CD and E or E will not be available so I need to calculate the average of AB and CD. As I said, my knowledge of programming is very limited so if you could provide code snippet with explanation of each step and where to plug in my session variables I would appreciate it very much. Thanks in advance for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I calculate the Average (Mean) for Interpreted Java?

#2 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1199
  • View blog
  • Posts: 7,306
  • Joined: 07-September 06

Re: How do I calculate the Average (Mean) for Interpreted Java?

Posted 02 August 2009 - 02:54 PM

Moved to web developmen. It isn't Javascript.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1