CS 1043 Lab 8
Childress
Topics covered in this Lab: Arrays and a Java IDE.
1. Write a class and name it ArrayOps. The class will have:
a. One static method named main.
b. One instance field named data of type integer array.
c. Write one constructor called ArrayOps with one argument. Make a deep copy of the data.
d. Three instance methods: display, reverse and findMin.
2. There will be one static method named “main” (as in all the previous lab assignments). Copy and past the main method given here into your class:
public static void main( String [] args )
{
/*
int [] input = { 0, 1, -2, -3, 4, 5, -6, -7, 8, 9 };
ArrayOps testObj = new ArrayOps( input ); // constructor
System.out.println(
"\nObject's index for the smallest value is: " +
testObj.findMin() + "\n" );
// 1. Reference the display-method to print the array contents.
// 2. Reference the reverse-method to the array order.
// 3. Reference the display-method to display the reversed
// array.
// 4. Reference the findMin-method to return the index of
// the smallest value stored in the reversed array:
// int mindex = ?
System.out.println(
"\nObject's index for the smallest value after reverse is : " +
mindex + "\n" );
*/
}
3. Create a private instance field named data of type int-array in your class.
4. Write the constructor ArrayOps with one argument. Use the input argument to create a deep copy of the input array. The variable name “data” is the reference to the deep copy.
5. Write a method called display. This method has no formal parameter inputs and no return value. This method will print the data array to the terminal screen (prints to what is known as standard output).
6. Write an instance method called reverse that returns nothing. The method should have no formal parameters. The method should do an in-place reversal of the elements stored in the data array. Do not use any additional arrays to reverse the order. See the Swap example on how to swap values.
7. Write an instance method called findMin that returns type int. The method has no formal parameters. The method should locate and return the index of the smallest value stored in the data array.
8. Submit your program to the Lab TA by the due date.