Designing Java Programs using 1-Dimensional Arrays

We shall complete the following exercises in order to improve our skills to:

  1. Design methods to sort a single single-dimensional array
  2. Design methods to sort parallel arrays
  3. Design methods to binary search in sorted arrays
  4. Design methods to process text/character files
  5. Combine methods into a single program

Exercises 1 - 3. Comparing three sorting algorithms

Implement three sorting algorithms, each in a Java method. These methods are:

  1. (Exercise 1) Selection Sort
    public static void selectionSort(int[] arr)
    
  2. (Exercise 2) Bubble Sort
    public static void bubbleSort(int[] arr)
    
  3. (Exercise 3) Insertion Sort
    public static void insertionSort(int[] arr)
    

Exercises 4 - 6. Sorting Parallel Arrays (Parallel Sort)

Implement three sorting algorithms, each in a Java method. These methods are:

  1. (Exercise 4) Selection Sort of Parallel Arrays
    public static void parallelSelectionSort(int[] dataArr, int[] keyArr)
    
  2. (Exercise 5) Bubble Sort of Parallel Arrays
    public static void parallelBubbleSort(int[] dataArr, int[] keyArr)
    
  3. (Exercise 6) Insertion Sort of Parallel Arrays
    public static void parallelInsertionSort(int[] dataArr, int[] keyArr)
    

(Exercise 7) Implement the binary search algorithm. The array returns the index of key if it is found. If it is not, return -(insertion point+1). If the algorithm is implemented correctly, the low index is the insertion point.

public static int binarySearch(int[] arr, int key)

(Exercise 8) Implement the linear search algorithm. The array returns the index of key if it is found; otherwise, -1.

public static int linearSearch(int[] arr, int key)

(Exercise 9) Additionally, write a program that generate a large random arrays, and compare elapsed times of the two search algorithms.

Exercises 10 - 12. Using Arrays to Process Files

(Exercise 10) Write the following Java method that returns the number of lines in the given file.

public static int getNumberOfLines(String inFilePath) throws FileNotFoundException

(Exercise 11) Write the following Java method that returns the all lines in the given file.

public static String[] getAllLines(String inFilePath) throws FileNotFoundException

(Exercise 12) Write a Java program that uses the above methods, convert all letters from lower case to upper case if any. A user would use the program in the fashion exhibited by the example below:

java UpperToLower input.txt output.txt