hi there
i'm storing ints in a vector and want to be able to work out the average of the int values
the functions below should do it but i am only getting the last value returned not the average of all of them
can anyone see where i'm going wrong
public void averageSwing ( )
{
int totalSwing = 0;
int temp = 0;
int numOfResults = swingsStore.size( );
for ( int i = 0; i < numOfResults; i++ )
{
Integer total = getVect( i ); // gets the value as an Integer
temp = total.intValue( ); // gets int value from Integer
totalSwing += temp; // works out total
}
average = totalSwing / numOfResults; // works out average
for ( int j = 0; j < numOfResults; j++)
{
swingsStore.removeElementAt( j );
}
}
public Integer getVect( int i )
{
return (Integer ) swingsStore.elementAt( i ); //gets the Integer value
}
public int getAverageSwing( )
{
return average; // returns the average value
}
thanks
ewan
i'm storing ints in a vector and want to be able to work out the average of the int values
the functions below should do it but i am only getting the last value returned not the average of all of them
can anyone see where i'm going wrong
public void averageSwing ( )
{
int totalSwing = 0;
int temp = 0;
int numOfResults = swingsStore.size( );
for ( int i = 0; i < numOfResults; i++ )
{
Integer total = getVect( i ); // gets the value as an Integer
temp = total.intValue( ); // gets int value from Integer
totalSwing += temp; // works out total
}
average = totalSwing / numOfResults; // works out average
for ( int j = 0; j < numOfResults; j++)
{
swingsStore.removeElementAt( j );
}
}
public Integer getVect( int i )
{
return (Integer ) swingsStore.elementAt( i ); //gets the Integer value
}
public int getAverageSwing( )
{
return average; // returns the average value
}
thanks
ewan