Starting from:
$35

$29

Project Seven An Array Festive Solution




Purpose: The purpose for this project is to reinforce the knowledge learned in Chapter 7.




Objectives:

Apply linear search algorithm
Apply select sort algorithm



Apply array iteration skill



Problem description:




Write the following eight methods and write a main function to test these methods




return the index of the first occurrence of key in arr



if key is not found in arra, return -­‐‑1



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




soert the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])
print out all array elements. 5 elements per line



public static void printArray(int arr[])




assign each element in array with a random number



between 1 and 100, inclusive



public static void initializeArray(int arr[])




find the range of all array elements

the range is defined as the difference between the largest and smallest elements public static int range(int arr[])
find the largest element in array



public static int largst(int arr[])




find the smallest element in array public static int smallest(int arr[])



find the average value of all elements in array public static double average(int arr[])
Sample pseudo code for main function

Declare an int array of size 10



Initialize the array by calling initializeArray function



Print out the array by calling printArray function
Print out the largest and smallest value of the array by using System.out.prinln and calling largest and smalles functions
Print out the range of the array






Print out the average of the array elements
Ask user to enter a search key



Call the linearSearch function with array and key. Based on result, print out appropriate message



Call the selectSort function to sort the array.



Print out array again to see the sorted array



Use Online Resource:




You may search on line to find the linear search and select sort algorithms.




Submission:

Submit the YourProj07.java file via blackboard link. The due date will be announce on blackboard

More products