This is not the correct lab quiz

This is the lab quiz from last semester

CS 101/101-E, Fall 2004

Lab quiz 3

Week of 6 Dec 2004


General notes

A couple of notes on the lab quiz:



For this lab quiz, you are to submit a single file named which contains an ArrayManipulation class.  No template is being given for this lab quiz.  The class must have only three methods, which are described in more detail below: reverse(), has(), and print().  You are welcome to put in other methods (in particular, a main() method), although they will not affect your grade.



The class should have the following three methods.  All methods need to be public AND static.

  1. has(): this method takes in two parameters, an int array and an element to search for in that array.  If the element is found in the array, the index where the element is located is returned (as an int).  If the element occurs multiple times in the array, only the index of the first occurrence is to be returned.  If the element is not found in the array, -1 is returned.
  2. reverse(): this method takes in an int array, and returns a NEW array of type int[] (i.e., the method return type is int[]).  The returned array should have the same elements as the passed array, but in reverse order.
  3. print(): this method takes in an int array as the parameter, and returns no value.  It prints the array on a SINGLE line, with spaces separating the values.



Make sure each of the methods are named EXACTLY as specified.  The names of the other methods, are used by our test code to grade your assignment.  If they are not exactly as specified, you will get a zero for pretty much all of the lab quiz.


main() method

There is no main() method required in the ArrayManipulation class - you are welcome to include one for testing purposes (it will not affect your grade one way or the other if it is included).  A sample main() method you may want to put in your class is shown below with the corresponding output.


Sample usage

The following main() method will produce the following output

Sample main() method:

public static void main (String args[]) {
    int[] array1 = { 1, 2, 3, 4, 5 };
    System.out.println ("Array has element 3: " + has(array1, 3));
    System.out.println ("Array has element 6: " + has(array1, 6));
    System.out.print ("Original array: ");
    int[] array2 = reverse (array1);
    System.out.print ("Reversed array: ");


Array has element 3: 2
Array has element 6: -1
Original array: 1 2 3 4 5
Reversed array: 5 4 3 2 1


Submit only the file here.