/* Author : Michael Robinson Program : bubbleSorter.java Purpose : To present the bubble sort using constructors and classes I implemented two forms of sorting int and String arrays. The first implementation uses the BubbleSort.class which is a Constructor that accepts arrays of int and arrays of String. The second implementation uses the bubbleSort method in the IntBubbleSort class to sort and array of ints, and the bubbleSort method in the StringBubbleSort class, to sort and array of Strings. So it uses three programs, this program, the intBubbleSorter.class that sorts ints, and the stringBubbleSorter.class that sorts Strings. This section can be expanded to accept arrays of floats, doubles, and all other primitive types. Updated : July 22, 2099 */ public class bubbleSorter { // Create global arrays with test intValues. public static int intValues1[] = { 89, -9, 3, 0, -1, 5, 7, 6, 0, 34, 23, -3, 4, 36 }; public static String stringValues1[] = { "zzz", "aaa", "cdet", "abcsd", "gatr" }; public static int intValues2[] = { 5, 1, 4, 2, 12, 90, -9, -1, 5, 7, 6, 0, 34, 23, -3, 4, 36 }; public static String stringValues2[] = { "one", "two", "five", "six", "ten" }; public static int intValues3[] = { 90, 6, 4, 2, 12, 7, 01, 13, -1, 5, 7, 6, 0, 34 }; public static String stringValues3[] = { "James", "Mariana", "999", "Sebastian", "Dan" }; public static void displayIntArray( int array[] ) { for ( int element : array ) //ENHANCED LOOP { System.out.print( element + " " ); } }//end public static void displayIntArray( int array[] ) public static void displayStringArray( String array[] ) { for( String element : array ) //ENHANCED LOOP { System.out.print( element + " " ); } }//end public static void displayStringArray( String array[] ) public static void useOneConstructor() { System.out.println( "\n\nBubble sort using a constructor" ); System.out.println( "-------------------------------" ); //create an object no data passed BubbleSort one = new BubbleSort(); //********************************************************* System.out.print( "\nOriginal: " ); displayIntArray( intValues2 ); //create an object passing an int array BubbleSort two = new BubbleSort( intValues2 ); //get back the array sorted int arrayInt2[] = two.getIntBubbleSort(); System.out.print( "\nSorted : " ); displayIntArray( arrayInt2 ); //********************************* System.out.print( "\n\nOriginal: " ); displayStringArray( stringValues2 ); //create an object passing a String array BubbleSort three = new BubbleSort( stringValues2 ); //get back the array sorted String arrayString2[] = three.getStringBubbleSort(); System.out.print( "\nSorted : " ); displayStringArray( arrayString2 ); //********************************************************* System.out.println( "\n\nModify data in arrays" ); System.out.println( "---------------------" ); System.out.print( "Original: " ); displayIntArray( intValues3 ); //modified array values for object one one.setIntBubbleSort( intValues3 ); //get back the array sorted int arrayInt3[] = one.getIntBubbleSort(); System.out.print( "\nSorted : " ); displayIntArray( arrayInt3 ); //********************************* System.out.print( "\n\nOriginal: " ); displayStringArray( stringValues3 ); //modified array values for object one one.setStringBubbleSort( stringValues3 ); //get back the array sorted String arrayString3[] = three.getStringBubbleSort(); System.out.print( "\nSorted : " ); displayStringArray( arrayString3 ); }//end public static void useOneConstructor() public static void useMultipleClasses() { System.out.println( "\n\n\nBubble sort using multiple classes" ); System.out.println( "----------------------------------" ); //********************************************************* System.out.print( "Original: " ); displayIntArray( intValues1 ); //Sort the numeric array. IntBubbleSort.bubbleSort( intValues1 ); System.out.print( "\nSorted : " ); displayIntArray( intValues1 ); //********************************************************** System.out.print( "\n\nOriginal: " ); displayStringArray( stringValues1 ); //Sort the string array. StringBubbleSort.bubbleSort( stringValues1 ); System.out.print( "\nSorted : " ); displayStringArray( stringValues1 ); }//end public static void useMultipleClasses() public static void main( String args[] ) { useOneConstructor(); useMultipleClasses(); System.out.println( "\n--------------------------" ); System.out.println( "End of BubleSorter Program" ); }//end public static void main(String[] args) }//end public class bubbleSorter