import java.util.Scanner;

/*
	A class to help do some calculations.
	TODO:
	-Change from ints to doubles for the xArray.
	-Allow the calculations without frequences.	
*/

public class Stats{

	public static void main(String[] args) throws Exception{
		System.out.print("Enter your x values: ");
		int[] xArray = parseInput();
		System.out.print("Enter the frequencies: ");
		int[] fArray = parseInput();
		if(fArray.length != xArray.length){
			System.out.println("There must be the same number of x values as frequencies!");
			throw new Exception();
		}

		double mean = calcMean(xArray, fArray);
		double sd = calcStandardDev(xArray, fArray);
		System.out.println("The mean is: " + mean);
		System.out.println("The Standard Deviation is: " + sd);
	}

	private static double calcStandardDev(int[] xArray, int[] fArray){
		double sd = calcSDNumerator(xArray, fArray);
		sd = sd / sumFrequencies(fArray);
		sd = Math.sqrt(sd);
		return sd;
	}

	private static double calcSampleStandardDev(int[] xArray, int[] fArray){
		double ssd = calcSDNumerator(xArray, fArray);
		ssd = ssd / (sumFrequencies(fArray) - 1);
		ssd = Math.sqrt(ssd);
		return ssd;
	}

	private static double sumFrequencies(int[] fArray){
		double sum = 0;
		for (int i = 0; i < fArray.length; i++){
			sum += fArray[i];
		}
		return sum;
	}

	//Utility method for calculating the numerator
	//of the Standard Deviation calculation.
	private static double calcSDNumerator(int[] xArray, int[] fArray){
		double numerator = 0;
		double mean = calcMean(xArray, fArray);
		for (int i = 0; i < xArray.length; i++){
			double diff = xArray[i] - mean;
			double diffSqrd = diff * diff;
			numerator += diffSqrd * fArray[i];
		}
		return numerator;
	}

	private static double calcMean(int[] xArray, int[] fArray){
		double mean = 0;
		for(int i = 0; i < xArray.length; i++){
			double weighting = xArray[i] * fArray[i];
			mean += weighting;
		}
		mean = mean / sumFrequencies(fArray);
		return mean;
	}

	private static int[] parseInput(){
		Scanner reader = new Scanner(System.in);
		String xValues = reader.nextLine();
		String[] stringArray = xValues.split(" ");
		int[] xArray = new int[stringArray.length];
		for (int i = 0; i < stringArray.length; i++) {
			try {
		        	xArray[i] = Integer.parseInt(stringArray[i]);
			} catch (NumberFormatException nfe) {
				System.out.println(stringArray[i] +  " Is not a valid number.");
			};
		}
		return xArray;
	}
}

@@ -159,17 +159,16 @@
 quences.
-%09
 %0A*/%0A%0Apub
@@ -639,16 +639,70 @@
 Array);%0A
+%09%09double ssd = calcSampleStandardDev(xArray, fArray);%0A
 %09%09System
@@ -797,16 +797,82 @@
  + sd);%0A
+%09%09System.out.println(%22The Sample Standard Deviation is: %22 + ssd);%0A
 %09%7D%0A%0A%09pri
@@ -1257,32 +1257,219 @@
 return ssd;%0A%09%7D%0A%0A
+%09/*%0A%09%09Sums up the totals of the frequencies.%0A%09%09This has been extracted as it is used as (at least part of)%0A%09%09the denominator on both Standard Deviation and Sample Standard Deviation.%0A%09*/%0A
 %09private static 
@@ -1611,17 +1611,17 @@
 ;%0A%09%7D%0A%0A%09/
-/
+*
 Utility 
@@ -1660,12 +1660,9 @@
 ator
-%0A%09//
+ 
 of t
@@ -1682,17 +1682,20 @@
 eviation
- 
+%0A%09 %09
 calculat
@@ -1704,140 +1704,482 @@
 n.%0A%09
-private static double calcSDNumerator(int%5B%5D xArray, int%5B%5D fArray)%7B%0A%09%09double numerator = 0;%0A%09%09double mean = calcMean(xArray, fArray);
+%09This part has been extracted because it is used for both%0A%09%09Standard Deviation & Standard Deviation.%0A%09*/%0A%09private static double calcSDNumerator(int%5B%5D xArray, int%5B%5D fArray)%7B%0A%09%09double numerator = 0;%0A%09%09//Get the mean to be used for calculating the differences of each x value.%0A%09%09double mean = calcMean(xArray, fArray);%0A%0A%09%09//For each x value we work out the difference between x and the mean%0A%09%09//We square each of these values and multiple by the frequency%0A%09%09// and add them up.
 %0A%09%09f
@@ -2601,24 +2601,122 @@
 n mean;%0A%09%7D%0A%0A
+%09/*%0A%09%09Takes a list of numbers on the command line and returns them as an array%0A%09%09of integers.%0A%09*/%0A
 %09private sta

Add comments.