import CSLib.*;
public class NumberList
{
	public static int input (InputBox box, int [] list)
	{
		//Prompt the user for how many items in list
		box.setPrompt ("How many items in the list?");
		int n = box.readInt();
		
		//Get each number from the user, one at a time
		for (int k=0; k<n; k++)
		{
			//Prompt the user for next number
			box.setPrompt ("Next number:");
			list [k] = box.readInt();
		}
		return n;
	}
	
	//The following methods process only the first n items in the list
	public static int average (int [] list, int n)
	{
		int sum = 0;
		for (int k=0; k<n; k++)
		{
			sum = sum + list [k];
		}
		return sum / n;
	}
	
	public static void display (OutputBox box, int [] list, int n)
	{
		for (int k=0; k<n; k++)
		{
			box.println (list [k]);
		}
		box.println ();  //double space
	}
	
	//The following method finds the smallest item in a list of integers
	public static int smallest (int [] list, int n)
	{
		int smallestSoFar;
		
		//The following focuses on smallestSoFar,
		//a variable that is compared with each item
		//in the list in succession.  As smaller items
		//are encountered, they are assigned to the variable
		//smallestSoFar.
		smallestSoFar = list[0];
		for (int k=1; k<n; k++)
		{
			if (list[k] < smallestSoFar)
			{
				smallestSoFar = list[k];
			}
		}
		return smallestSoFar;
	}		
	
	public static int largest (int [] list, int n)
	{
		int largestSoFar;
		
		//The following focuses on largestSoFar,
		//a variable that is compared with each item
		//in the list in succession.  As smaller items
		//are encountered, they are assigned to the variable
		//largestSoFar.
		largestSoFar = list[0];
		for (int k=1; k<n; k++)
		{
			if (list[k] > largestSoFar)
			{
				largestSoFar = list[k];
			}
		}
		return largestSoFar;
	}	
	
	
	
	
	public static int average (int [] list)
	{
		int sum = 0;
		for (int k=0; k<list.length; k++)
		{
			sum = sum + list [k];
		}
		return sum / list.length;
	}
	
	public static void display (OutputBox box, int [] list)
	{
		for (int k=0; k<list.length; k++)
		{
			box.println (list [k]);
		}
		box.println ();  //double space
	}
	
	//The following calculates the standard deviation of list
	public static int sd (int [] list, int avg)
	{
		//lab exercise
		//HINT:  Copy and paste the code for average () from above and modify
		int sum = 0;
		for (int k=0; k<list.length; k++)
		{
			sum = sum + (list [k] - avg)*(list [k] - avg);
		}
		return (int)Math.sqrt (sum / list.length);
	}
	
	//The following method finds the smallest item in a list of integers
	public static int smallest (int [] list)
	{
		int smallestSoFar;
		
		//The following focuses on smallestSoFar,
		//a variable that is compared with each item
		//in the list in succession.  As smaller items
		//are encountered, they are assigned to the variable
		//smallestSoFar.
		smallestSoFar = list[0];
		for (int k=1; k<list.length; k++)
		{
			if (list[k] < smallestSoFar)
			{
				smallestSoFar = list[k];
			}
		}
		return smallestSoFar;
	}
	
	public static int largest (int [] list)
	{
		int largestSoFar;
		
		//The following focuses on largestSoFar,
		//a variable that is compared with each item
		//in the list in succession.  As smaller items
		//are encountered, they are assigned to the variable
		//largestSoFar.
		largestSoFar = list[0];
		for (int k=1; k<list.length; k++)
		{
			if (list[k] > largestSoFar)
			{
				largestSoFar = list[k];
			}
		}
		return largestSoFar;
	}
	
	//The following function returns the location of the first
	//occurrence of "number" in "list".  If the number is not in
	//the list, then it returns -1.
	public static int find (int number, int [] list)
	{
		//Cycle (loop?) through the list and check each
		//item to see if it's the same as "number"
		//If it is, then return index + 1
		//If you cycle throught the entire list and don't
		//find it, then return -1
		
		for (int k=0; k<list.length; k++)
		{
			if (list[k] == number)
			{
				return k+1;
			}
		}
		
		return -1;
	}	
}
