Problem

Fix the ErrorsFind all the errors in the following program and correct them so that the pr...

Fix the Errors

Find all the errors in the following program and correct them so that the program does what it is supposed to do. There are syntax errors and semantic (logical) errors. The easiest way to do this is with your compiler’s assistance.

The following program is supposed to create a class ArrayHandler with three methods:

a. A constructor ArrayHandler(int n) that creates an array, arr, of length n containing random elements in the range 0 to n– 1.


b. partitionArray(), which partitions the array around the fi rst element a = arr[0] of arr.

This means the array is reordered so that:

• a is repositioned in the array,

• all elements “to the left” of a are less than or equal to a, and

• all elements “to the right” of a are greater than or equal to a.

For example if arr is: [ 7, 2, 15, 9, 13, 26, 36, 1], then one possible partitioning rearranges arr as [2, 1, 7, 15, 9, 13, 26, 36].


c. PrintArray(), which displays the contents of the array arr.Class ArrayHandler{  private int[] arr;

  ArrayHandler(int n)  {      for (int j = 0; j

  ArrayHandler() // Default constructor sets up an empty array  {       ArrayHandler(0);  }

  public void partitionArray()  {       int temp[] = new int (arr.length);       // This iterates through the array element by element, from the second element until the end.       // If an element is smaller than the fi rst element then that element is copied to a new array.       // After going through the whole array, the fi rst element is then copied to the new array.       // The original array is once again examined element by element from the second element.       // If an element is larger than the fi rst element (or equal to it) then that element is copied       // to the new array.

       int index = 0;       for (int k = 1; k = arr[0] temp[index] = arr[k]; index++  }}

public void printArray(){       for int m = 0; m

public static main(String args){       ArrayHandler t = new ArrayHandler(25);       t.printArray(); t.partitionArray; t.printArray();}}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 10
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT