W10 Homework Assignment

Solution:


	
	/**
	 * This method allocates and fills an array with the values from the specified low to the specified high;
         * for example, if low is -1 and high is 3, then the array will hold -1, 0, 1, 2, 3
	 * @param low - the lowest value in the array
	 * @param high - the highest value in the array
	 * @return - reference to the created non-empty array of doubles
	 */
	public static double[] fillArray( int low, int high ) {
		double[] nums = new double[high-low+1]; // create the actual array just big enough to hold all the values
		int index = 0;
		for(int i=low; i<=high; i++) {
			nums[index++] = i;	// stuff the values into the array at specific locations
		}
		return nums;
	}
	
	
	/**
	 * This method computes the average of the values in the specified array
	 * @param numArray - reference to an array of values, created elsewhere
	 * @return - the average of the values within the array
	 */
	public static double getArrayAvg( double numArray[] ) {
		double sum = 0.0;
		for(int i=0; i<numArray.length; i++) {
			sum += numArray[i];	// add to the sum by retrieving values from specific array locations
		}
		return sum/numArray.length;
	}