In this lab we will gain familiarity with arrays through implementing the ‘bubble-sort’ method. We will also use pseudo code to help identify the algorithm required to solve a programming project.

 

Following the completion of the program you should be able to:

  • Prepare pseudo code before coding implementation.
  • Instantiate and iterate through an integer array
  • Accurately create and implement the bubble-sort method for your array
  • Gain practice in writing methods

 

Programming Problem:

Create a class called ArraySorter.java that contains the following methods:

 

public static void bubbleSortIncrease(int[] anArray)

public static String printArray(int[] anArray)

 

The bubble sort algorithm examines all adjacent pairs of elements in the array from the beginning to the end and interchanges any two elements that are out of order. Each interchange makes the array more sorted than it was before and when the end of the array is reached it will be totally sorted.

( http://en.wikipedia.org/wiki/File:Bubble-sort-example-300px.gif )

 

The printArray method will iterate through the array and concatenate each integer value to a String variable.

 

Part #1:

Prepare and submit a legibly hand written or typed pseudo code version of this programming project. Your pseudo code should include all the variables you will need as well a plan English description of your logic. If your submission is typed, please include it in your .zip file submission.

 

 

 

Part #2:

Using your pseudo code as a guide, create and code your ArraySorter.java solution in Eclipse. Submit your solution and pseudo code.

 

Program Requirements:

  1. Name your classes as outlined above.
  2. Follow Java naming conventions for all variables.
  3. Use appropriate indentation for program.
  4. Practice good commenting

 

In your main() method you must instantiate, sort, and print the following two int arrays

 

{4, 87, 14, 65, 56, 2, 352, 1, 0, 677, 221, 5}

{90, 34, 4, 58, 91, 100, 655, 324, 111, 101, 76}

 

Sample Output:

Array One: {4, 87, 14, 65, 56, 2, 352, 1, 0, 677, 221, 5}

Bubble Sorted Array One: {0, 1, 2, 4, 5, 14, 56, 65, 87, 221, 352, 677}

 

Array Two: {90, 34, 4, 58, 91, 100, 655, 324, 111, 101, 76}

Bubble Sorted Array Two: {4, 34, 58, 76, 90, 91, 100, 101, 111, 324, 655}

 

 

 

    • 10 years ago
    BEST SOLUTION ANSWER
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      arraysorter_java.zip