write comment on each line in the come plz>> package Checkpoint; /** * A class to implement
Question:
write comment on each line in the come plz>>
package Checkpoint; /** * A class to implement a set of sorting algorithms. * */ public class Sorts implements Sorting{
@Override public void Sorting() { }
@Override /** * Sort the array of strings, v, into ascending lexicographic order using Insertion sort. * No errors may be reported and no exceptions may be thrown. * If an error is detected or an exception occurs, return without modifying the array. * * @param a The array to be sorted. */ public void insertionSort(String[] a) { for (int j = 1; j < a.length; ++j) { String key = a[j];
int i = j - 1;
while ((i >= 0) && (a[i].compareTo(key) > 0)) {
a[i + 1] = a[i];
i = i - 1;
a[i + 1] = key; } } } }
---------------
package Checkpoint; import java.util.Arrays; import java.util.Random; public class Checkpoint1Driver {
public static void main(String[] args) {
// Checkpoint 1 testing int insertionSortPassCount = 0; insertionSortTestCase(); // ------------X------------
// Checkpoint 2 testing // Note this timings will differ based on the processor System.out.println(" Efficiency Tests:"); System.out.println("1-Size 1000: "+efficiencyTesting(1000)); System.out.println("2-Size 5000: "+efficiencyTesting(5000)); System.out.println("3-Size 10000: "+efficiencyTesting(10000)); System.out.println("4-Size 50000: "+efficiencyTesting(50000)); System.out.println("5-Size 75000: "+efficiencyTesting(75000)); System.out.println("6-Size 100000: "+efficiencyTesting(100000)); // --------------X--------------
}
static void insertionSortTestCase() { String[] unsorted_test_1 = { "g", "r", "s", "n", "b", "q", "l", "m", "e", "a", "v", "i" }; String[] sorted_test_1 = { "a", "b", "e", "g", "i", "l", "m", "n", "q", "r", "s", "v" }; Sorting sorter = new Sorts(); try { sorter.insertionSort(unsorted_test_1); if (Arrays.equals(unsorted_test_1, sorted_test_1)) { System.out.println("Test Pass"); } else {
System.out.println("Test Fail"); } } catch (Exception e) { System.out.println("Test Fail"); } }
public static int testingOutcoms(String text, String[] unsorted_test_1, String[] sorted_test_1) { if (Arrays.equals(unsorted_test_1, sorted_test_1)) { System.out.println(text + " Test Pass"); return 1; } else { System.out.println(text + " Test Fail"); return 0; } }
public static double efficiencyTesting(int NUMITER) {
String[] input = new String[NUMITER]; long startTime, endTime; double duration;
Random randomGenerator = new Random(); Sorting sorter = new Sorts();
for (int i = 0; i < NUMITER; i++) { input[i] = randomGenerator.nextInt() + ""; }
startTime = System.currentTimeMillis(); sorter.insertionSort(input); endTime = System.currentTimeMillis(); duration = ((double) (endTime - startTime)); return duration; }
}
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates