CS 1711 Recitation Laboratory 8:
The Array Utility Class

There is nothing to turn in for this recitation. You will get full credit for it if you show up and make an honest attempt to work on the material presented here.

Case Study 9: Arrays as parameters - the ArrayUtility class

Create a project called cs09. All of the classes in this project will be in the arrayutiliuytpkg package.

The ArrayUtility class, which is patterned after the Math class, contains static methods that perform various operations on arrays of integers.

Create a class called ArrayUtility that will contain the following static methods.
You can find a skeleton for this code here.
Load this into your browser and use cut and paste to put it into an eclipse class.

Create an ArrayUtilityTester class to test the methods.

   public static void printForwards(int [] array); // outputs array
   public static void printBackwards(int [] array); // outputs array in reverse order
   public static int getSum(int [] array); // returns sum of array values
   public static double getAverage(int [] array); // returns average of array values
   public static int getMax(int [] array); // returns maximum value in array
   public static int getMin(int [] array); // returns minimum value in array
   public static int [] reverse(int [] array); //returns new array with elements reversed
   public static int [] clone(int [] array); // returns a new array with copy of array
   public static int find(int [] array, int target); // returns first index of target in array
                                                     // or -1 if not there
Test the methods on some arrays of int's.
Make sure that all of your methods work for empty arrays.

If you have time you can also implement the following methods:

   public static void reverseInPlace(int [] array); //modifies the array so that the order of the elements are reversed
   public static boolean isSortedForward(int [] array); //returns true if the array is sorted smallest to largest
   public static boolean isSortedBackwards(int [] array); //returns true if the array is sorted largest to smallest
   public static boolean isSorted(int [] array); //returns true if the array is sorted either way
   public static boolean isConstant(int [] array); //returns true if all of the elements are the same
And here is one that is slightly harder:
   public static int getSecondLargest(int [] array); // returns second largest element of the array.
       // this should return the same value as array[1] if the array is sorted
       // in increasing order.  Do not modify the array.
       // Make sure your solution handles a small array gracefully.