import java.util.*; public class A1 { /** This method constructs an array of integers of a given size, with random elements ranging uniformly from 0 up to but not including a given integer value. It assumes that the size is nonnegative. @param size the given size @param r a Random object to generate the array elements. @param bound the given integer value @return the constructed array */ public static int[] buildRandomArray(int size, Random r, int bound) { int[] a = new int[size]; for (int i=0; itrue if the array is sorted, and false otherwise */ public static boolean hasDuplicates(int[] a, DuplicateTester d) { if (d.isSorted(a)) { System.out.print("testing sorted array -- "); return d.hasDuplicatesSorted(a); } else { System.out.print("testing unsorted array -- "); return d.hasDuplicatesUnsorted(a); } } /** A test program for the Duplicate Tester class */ public static void main(String args[]) { DuplicateTester dt = new DuplicateTester(); Random r = new Random(1); int[] a; a = buildRandomArray(1,r,100); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomArray(25,r,100); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomArray(25,r,1000); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomArray(25,r,10000); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomSortedArray(1,r,10); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomSortedArray(25,r,100); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomSortedArray(250,r,100); System.out.println(" " + hasDuplicates(a,dt)); a = buildRandomSortedArray(2500,r,100); System.out.println(" " + hasDuplicates(a,dt)); } }