public static void shuffleArray ( int[] anArray ) public static void printArray ( int[] anArray )
To shuffle an array you can use this basic algorithm:
The method printArray() will print the contents of an array in a nicely formatted fashion such that there is at least two blank spaces between adjacent numbers and no more than five numbers to a line.
In your method main() you will define an array. Print out the contents. Shuffle the array and print out the result. Shuffle the array again and print out the contents. Thus your main will look like:
int[] theArray = { 3, 5, 1, 7, 0, 9, 2, 6, 4, 8 };
printArray ( theArray );
shuffleArray ( theArray );
printArray ( theArray );
shuffleArray ( theArray );
printArray ( theArray );
The file that you will be turning in will be called Shuffle.java. You will follow the standard Java coding convention that I have appended below. The file will have a header of the following form:
/* File: Shuffle.java Description: Student Name: Student UT EID: Course Name: CS 303E Unique Number: TA: Date Created: Date Last Modified: */
public static boolean isSorted ( int[] a )Your method will return true if the array is sorted either in ascending or descending order. You may use two other helper methods to test if the array is sorted in either ascending or descending order.
In your method main() you will test whether the method isSorted() is working correctly or not. You will generate the following arrays:
int[] xArray = { 2, 4, 7, 9, 10 };
int[] yArray = { 93, 45, 28, -32, -79 };
int[] zArray = { 2, 4, 6, 8, 5, 10, 12 };
You will test if the above arrays are sorted and print out the
result.
The file that you will be turning in will be called TestSorted.java. You will follow the standard Java coding convention that I have appended below. The file will have a header of the following form:
/* File: TestSorted.java Description: Student Name: Student UT EID: Course Name: CS 303E Unique Number: TA: Date Created: Date Last Modified: */
You will follow the standard Java Coding Conventions. You can either view the HTML page or download the PDF or Postscript and print it out. There is a modification that I would like to make to the standard coding conventions. Please align the opening and closing braces vertically so that you can easily make out the blocks of code.
Use the turnin program to submit your Shuffle.java and TestSorted.java files. The TAs should receive your work by 5 PM, Sunday, 28 March 2004.