/**
 * A utility class that contains methods for calculating
 * various descriptive statistics.
 *
 * Each of the methods in this class has (one or more) known bugs
 * that can be found using careful white (open) box testing
 *
 * @author  Prof. David Bernstein
 * @version 1.0
 */
public class Statistics
{
    /**
     * Calculates the absolute value of a number
     *
     * @param x   The number
     * @return    The absolute value of x
     */
    public static double abs(double x)
    {
       return (-1 * x);       
    }
    


    /**
     * Calculates the maximum of two values
     *
     * @param a   One value
     * @param b   The other value
     * @return    The maximum of a and b
     */
    public static int max(int a, int b)
    {
       int        result;
       
       result = 0;
       if      (a > b) result = a;
       else if (a < b) result = b;

       return result;       
    }
    


    /**
     * Calculates the maximum value in an array
     *
     * @param data   The values
     * @return       The maximum value
     */
    public static int max(int[] data)
    {
       int result;

       result = data[0];
       
       for (int i=1; i<data.length; i++)
       {
          if (data[i] > result)
			    result = data[i];          
       }
       
       return result;       
    }
    
        


    /**
     * Calculates the minimum of two values
     *
     * @param a   One value
     * @param b   The other value
     * @return    The minimum of a and b
     */
    public static int min(int a, int b)
    {
       int        result;
       
       if (a > b) result = b;
       else       result = a;

       return result;       
    }



    /**
     * Calculates the minimum value in an array
     *
     * @param data   The values
     * @return       The minimum value
     */
    public static int min(int[] data)
    {
       int result;

       result = data[0];
       
       
       for (int i=1; i<data.length; i++)
       {
          if (data[i] < result) result = data[i];          
       }

       
       return result;       
    }
    



    /**
     * Calculates the mean of an array
     *
     * @param data   The raw data
     * @return       The mean of the raw data
     */
    public static double mean(int[] data)
    {
       double      result, total;
       
       total = 0.0;       
       for (int i=0; i<data.length; i++)
       {
          total += data[i];          
       }

       result = total / data.length;
       
       return result;       
    }



    /**
     * Calculates the sign of a number
     *
     * @param x   The number
     * @return    The sign of x (-1, 0, or 1)
     */
    public static int sign(double x)
    {
       int      result;
       

       result = 0;       
       if (x < 0) result = -1;
       else       result =  1;
       
       return result;       
    }
    
    
}
