Suppose numberList is an object of the class ArrayList. Give code that will output all the elements in numberList to the screen.  Write a class for sorting strings into lexicographic order that...

Suppose numberList is an object of the class ArrayList. Give code

that will output all the elements in numberList to the screen.


 Write a class for sorting strings into lexicographic order that follows the outline


of the class SelectionSort in Display 6.11 of Chapter 6. Your definition,


however, will use an ArrayList of the class ArrayList, rather than

an array of elements of type double. For words, lexicographic order reduces to


alphabetic order if all the words are in either all lowercase or all uppercase letters.


You can compare two strings to see which is lexicographically first by using


the String method compareTo. For strings s1 and s2, s1.compareTo(s2)


returns a negative number if s1 is lexicographically before s2, returns 0 if s1


equals s2, and returns a positive number if s1 is lexicographically after s2. Call


your class StringSelectionSort. A test program you can use to test your class


follows. (The program is included with the source code provided on the website


that accompanies this book.)


Import java.util.ArrayList;


public class StringSelectionSortDemo


{


 public static void main(String[] args)


 {


ArrayList b = new ArrayList();

 b.add("time");


 b.add("tide");


 b.add("clouds");


 b.add("rain");


 System.out.println("ArrayList values before sorting:");


 for (String e : b)


 System.out.print(e + " ");


 System.out.println();


 StringSelectionSort.sort(b);


 System.out.println("ArrayList values after sorting:");


 for (String e : b)


 System.out.print(e + " ");


 System.out.println();


 }


}


May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here