COW Q1N6 Arrays

Level 1

Complete the following methods in the ArrayPractice1 Class. Name: print Input: int [] array Output: nothing Action: print out all the elements of the array using a loop.

Name: printReverse Input: int [] array Output: nothing Action: print out all the elements of the array in reverse.

Name: printPositives Input: int [] array Output: nothing Action: print out all the positive numbers in the array.

Name: printNegatives Input: int [] array Output: nothing Action: print out all the negative numbers in the array.

Name: printEvens Input: int [] array Output: nothing Action: print out all the even numbers in the array.

Name: printOdds Input: int [] array Output: nothing Action: print out all the odd numbers in the array.

Name: printPositiveEvens Input: int [] array Output: nothing Action: print out all the positive even numbers in the array.

Name: printNegativeOdds Input: int [] array Output: nothing Action: print out all the negative odd numbers in the array. Level 2

Complete ArrayPractice2 Class. Do not assume the arrays have a specific length.

Name: sumArray Input: double [] values Output: double sum Action: calculates the sum of all the elements in the array.

Name: getAverageValue Input: double [] values Output: double average Action: calculates the average of all the elements in the array.

Name: sumSquaresOfDeviations Input: double [] values, double average Output: double sumDeviations Action: calculates the sum of all the deviations squared of each element from average.

Name: standardDeviation Input: double [] values Output: double deviation Action: calculates the standard deviation of the numbers in values Level 3

Complete ArrayPractice3 Class. Do not assume the arrays have a specific length.

Name: flip Input: double [] data Output: double [] flippedData Action: Creates a new array the same size as the old array. Each element of the new array should be equal to the negated value of the corresponding element in data.

Name: amplify Input: double [] data, double multiplier Output: double [] amplifiedData Action: Creates a new array the same size as the old array. Each element of the new array should be equal to the corresponding element in data multiplied by multiplier.

Name: cap Input: double [] data, int min, int max Output: double [] cappedData Action: Creates a new array the same size as the old array. Each element of the new array should be equal to the corresponding element in data unless it is less then min or greater than max. If it falls out of range then it should be set to min or max depending on whether it was too low or too high.

Name: evenOut Input: double [] data Output: double [] evenedOutData Action: Creates a new array the same size as the old array. Each element of the new array should be the average of the corresponding element in data and the two adjacent elements in data. The two elements at the end of evenedOutData should be an average of the last two elements in data. Level 4

Complete ArrayPractice4 Class. Do not assume the arrays have a specific length.

Name: print Input: String [] array Output: nothing Action: print out all the elements of the array

Name: combine Input: String [] arr1, String [] arr2 Output: String [] combined Action: combines the elements in the first array with the elements in the second array into one larger array.

Name: subArray Input: String[] arr, int i1, int i2 Output: String [] Action: returns an array that only includes the elements from the first index up to but not including the element at the second index.

Name: equal Input: String [] arr1, String [] arr2 Output: boolean areEqual Action: returns whether or not all the two arrays are exactly the same.

Name: contains Input: String[] arr, String word Output: boolean isThere Action: returns whether or not word is contained within the array Level 5

Complete ArrayPractice5 Class. Do not assume the arrays have a specific length.

Name: paintRainbow Input: Graphics g, Color [] theColors Output: nothing Action: paints to the screen a rainbow consisting of the colors in the array