How would I add standard deviation to my program? Please help.

New to Java and having trouble adding standard deviation to my program. Please help, it would be greatly appreciated!

package sales.report;

import java.util.Scanner;

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/**

*

* @author MILFHUNTER

*/

public class SalesReporter {

private double highestSales;

private double averageSales;

private SalesAssociate[] team;

private int numberOfAssociates;

public void getData()

{

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter number of sales associates:");

numberOfAssociates = keyboard.nextInt();

team = new SalesAssociate[numberOfAssociates +1 ];

for (int i = 1; i <= numberOfAssociates; i++)

{

team[i] = new SalesAssociate();

System.out.println("Enter data for associate " + i);

team[i].readInput();

System.out.println();

}

}

public void computeStats()

{

double nextSales = team[1].getSales();

highestSales = nextSales;

double sum = nextSales;

for (int i = 2; i <= numberOfAssociates; i++)

{

nextSales = team[i].getSales();

sum = sum + nextSales;

if (nextSales > highestSales)

highestSales = nextSales;

}

averageSales = sum / numberOfAssociates;

}

public void displayResults()

{

System.out.println("Average sales per associate is $" +

averageSales);

System.out.println("The highest sales figure is $" +

highestSales);

System.out.println();

System.out.println("The following had the highest sales");

for (int i = 1; i <= numberOfAssociates; i++)

{

double nextSales = team[i].getSales();

if (nextSales == highestSales)

{

team[i].writeOutput();

System.out.println("$" + (nextSales-averageSales)

+ "above the average.");

System.out.println();

}

}

System.out.println("The rest performed as follows");

for (int i = 1; i <= numberOfAssociates; i++)

{

double nextSales = team[i].getSales();

if (team[i].getSales() != highestSales)

{

team[i].writeOutput();

if (nextSales >= averageSales)

System.out.println("$" + (nextSales-

averageSales) + "above the average.");

else

System.out.println("$" + (averageSales -

nextSales) + "below the average.");

System.out.println();

}

}

}

public static void main(String[] args)

{

SalesReporter clerk = new SalesReporter();

clerk.getData();

clerk.computeStats();

clerk.displayResults();

}

}

Re: How would I add standard deviation to my program? Please help.

Re: How would I add standard deviation to my program? Please help.

Can you explain where your formula is for computing the desired value?

Re: How would I add standard deviation to my program? Please help.

public void computeStats()

{

double nextSales = team[1].getSales();

highestSales = nextSales;

double sum = nextSales;

for (int i = 2; i <= numberOfAssociates; i++)

{

nextSales = team[i].getSales();

sum = sum + nextSales;

if (nextSales > highestSales)

highestSales = nextSales;

}

averageSales = sum / numberOfAssociates;

sum = 0;

for ( int i = 1; i<= numberOfAssociates; i++)

{double diff = (averageSales-team[i].getSales());

sum = sum + diff*diff;

}

double variance = sum / ( numberOfAssociates-1 );

stdDev = sqrt (variance)

So I have worked on it some more in this is what I have...I get an error message(erroneous symbol) for stdDev = sqrt (variance)

Re: How would I add standard deviation to my program? Please help.

Quote:

I get an error message

Please post the full text of the error message.

Re: How would I add standard deviation to my program? Please help.

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: sqrt

at sales.report.SalesReporter.computeStats(SalesRepor ter.java:59)

at sales.report.SalesReporter.main(SalesReporter.java :104)

Java Result: 1

Re: How would I add standard deviation to my program? Please help.

Ok I fixed that...

should be Math.sqrt instead of sqrt

Having trouble displaying in results now when i run the program

Re: How would I add standard deviation to my program? Please help.

WilsonGTI45, I posted three links for you. I expect you to go through them.

db