JAVA PROGRAM Details:

I'm having a trouble with the print lines, i'm not sure where to start but i think I got the rest down correctly. Please if there is a mistake in this program, let me know or correct my current program below, this program should be compiled in JGRASP OR BLUEJ please try it to compile yourself too.

Thanksthe sort() method calls sortSublist(0,length-1) * * Write a DRIVER with a main() method to test your sorting algorithm. * It should do the following: * * 1. Generate a list of 50 random integers. * 2. Print out the unsorted list (with 5 integers per line). * 3. Sort the list. * 4. Print out the sorted list. * ***************************************************************************/ class SortableIntegerList { private int maxLength, // The length of the array length; // The length of the list (length <= maxLength) private int[] a; // An array with the integers in the list public SortableIntegerList (int mxLen) // Creates an empty list with maximum length mxLen { maxLength = mxLen; length = 0; a = new int[maxLength]; }



Optional Information:
Level: 2nd; Subject: Computer Science/Data Structure and Algorithm

Already Tried:
class SortableIntegerList
{
private int maxLength, // The length of the array
length; // The length of the list (length <= maxLength)
private int[] a; // An array with the integers in the list

public SortableIntegerList (int mxLen)
// Creates an empty list with maximum length mxLen
{
maxLength = mxLen;
length = 0;
a = new int[maxLength];
}

public void append (int value)
// Append the value to the end of the list
{
a[length] = value;
length++;
}

public void sort()
// Sort the list from smallest to largest
{
sortSublist(0,length-1);
}

private void sortSublist(int startIndex, int endIndex)
// Sort the sublist a[startIndex]...a[endIndex]
// IMPORTANT: This method must be recursive!
{
// YOUR CODE GOES HERE!
if ( endIndex >= startIndex.length -1 )
return;
int minIndex = endIndex;
for ( int index = endIndex + 1; index < startIndex.length; index++ )
{
if (startIndex[index] < startIndex[minIndex] )
minIndex = index;
}
int temp = startIndex[endIndex];
startIndex[endIndex] = startIndex[minIndex];
startIndex[minIndex] = temp;
sortSublist(startIndex, endIndex +1);
}

}

public void printList ()
/* Prints the values in the list to standard output with
five values per line, properly aligned in columns
*/
{
// YOUR CODE GOES HERE!


}

To start, I see a few issues with the provided program. Here are the changes you need to make:

1. In the `sortSublist` method, the condition `if ( endIndex >= startIndex.length -1 )` is incorrect. `startIndex` is an integer variable, not an array, so you cannot use `startIndex.length` to get its length. Instead, you should use `length` to get the length of the `a` array.

Here's the corrected version of the `sortSublist` method:

```java
private void sortSublist(int startIndex, int endIndex) {
if (endIndex >= length - 1)
return;

int minIndex = endIndex;
for (int index = endIndex + 1; index < length; index++) {
if (a[index] < a[minIndex])
minIndex = index;
}

int temp = a[endIndex];
a[endIndex] = a[minIndex];
a[minIndex] = temp;

sortSublist(startIndex, endIndex + 1);
}
```

2. In the `printList` method, you need to iterate through the elements of the `a` array to print them. You can use a loop and a counter to print 5 values per line. Here's the corrected version of the `printList` method:

```java
public void printList() {
for (int i = 0; i < length; i++) {
System.out.print(a[i] + " ");

// Print a new line every 5 values
if ((i + 1) % 5 == 0) {
System.out.println();
}
}
System.out.println();
}
```

Now, you can create a driver class with a `main` method to test the sorting algorithm. Here's an example:

```java
import java.util.Random;

public class SortableIntegerListDriver {
public static void main(String[] args) {
SortableIntegerList list = new SortableIntegerList(50);

// Generate a list of 50 random integers
Random random = new Random();
for (int i = 0; i < 50; i++) {
int randomNumber = random.nextInt(100);
list.append(randomNumber);
}

// Print out the unsorted list
System.out.println("Unsorted list:");
list.printList();

// Sort the list
list.sort();

// Print out the sorted list
System.out.println("Sorted list:");
list.printList();
}
}
```

To compile and run the program, you can use JGRASP or BlueJ by copying the corrected code into a Java file (.java) and running it through the IDE. Make sure to save the file with the correct name and extension (e.g., `SortableIntegerList.java` for the class containing the `SortableIntegerList` definition, and `SortableIntegerListDriver.java` for the driver class).