preview

The Comparison Of The Number Of Sets In The Maths

Decent Essays

public class StatCalc {

private int count; // Number of numbers that have been entered.

private double sum; // The sum of all the items that have been entered.

private double squareSum; // The sum of the squares of all the items.

/**

* Add a number to the dataset. The statistics will be computed for all

* the numbers that have been added to the dataset using this method.

*/

public void enter(double num) {

count++;

sum += num;

squareSum += num*num;

}

/**

* Return the number of items that have been entered into the dataset.

*/

public int getCount() {

return count;

}

/**

* Return the sum of all the numbers that have been entered.

*/

public double getSum() {

return sum;

}

/**

* Return the average of all the …show more content…

Methods are provided to return the following statistics for the set of numbers that have been entered: The number of items, the sum of the items, the average, the standard deviation, the maximum, and the minimum.
*/

public class StatCalc {

private int count; // Number of numbers that have been entered. private double sum; // The sum of all the items that have been entered. private double squareSum; // The sum of the squares of all the items. private double max = Double.NEGATIVE_INFINITY; // Largest item seen. private double min = Double.POSITIVE_INFINITY; // Smallest item seen.

public void enter(double num) {
// Add the number to the dataset. count++; sum += num; squareSum += num*num; if (num > max) max = num; if (num < min) min = num;
}

public int getCount() {
// Return number of items that have been entered. return count;
}

public double getSum() {
// Return the sum of all the items that have been entered. return sum;
}

public double getMean() {
// Return average of all the items that have been entered.
// Value is Double.NaN if count == 0. return sum / count;
}

public double getStandardDeviation() {
// Return standard deviation of all the items that have been entered.
// Value will be Double.NaN if count == 0. double mean = getMean(); return Math.sqrt( squareSum/count - mean*mean );
}

public double getMin() {
// Return the smallest item that has been entered.
// Value will be infinity if no items have

Get Access