public class SoccerScores { /** 11/7/2018 * This class stores winning scores for several teams * that play soccer. * Purpose: we want to put array processing into methods. * 1. find max, min, average * 2. copying arrays * 3. comparing arrays * 4. find duplicates * 5. linear search (we did 3 different versions) * 6. find duplicates in unsorted array * 7. sort the array (use 2 different algorithms: Selection Sort * and Bubble Sort) */ public static void main(String[] args) { // declare and initialize int[] scores = {3, 4, 2, 1, 0, 0, 0, 1, 5}; int max = findMax(scores); int min = findMin(scores); double average = calculateAverage(scores); System.out.println("max score is: " + max + " lowest score is: " + min + ". Average is: " + average); int[] copyScores = new int[scores.length]; makeCopy(scores, copyScores); // enhanced for loop for (int e: copyScores) { System.out.println(e + " "); } if (isEqual(scores, copyScores)) System.out.println("The copy is identical to the original."); int index = linearSearch3(scores, 0); if (index !=-1) System.out.println("the first occ of 0 is at: " + index); else System.out.println(0 + " does not occur in the array."); int num = linearSearch(scores, 1); System.out.println(1 + " occurs " + num + " times."); if (linearSearch2(scores, 5)) System.out.println("yes, at least one team got " + 5); selectionSort(copyScores); System.out.println("After sorting copyScores: "); for (int e: copyScores) { System.out.println(e + " "); } } /** this linear search searches for val in arr and returns the * number of times val occurs in the array. * @param arr the array to search * @param val is the value that you are searching for * @return count of how many times val occurs in array arr */ public static int linearSearch(int[] arr, int val) { int count=0; // declare an init count for (int elt: arr) if (elt == val) count++; return count; } /** this linear search searches for val in arr and returns true * if val occurs in the array, false otherwise. * @param arr the array to search * @param val is the value that you are searching for * @return true if val occurs in array arr, false otherwise */ public static boolean linearSearch2(int[] arr, int val) { for (int elt: arr) if (elt == val) return true; return false; } /** this linear search searches for val in arr and returns the * index of the first occurrence of val in the array. * @param arr the array to search * @param val is the value that you are searching for * @return integer which is the index where val occurs in array arr * and -1 if val does not occur */ public static int linearSearch3(int[] arr, int val) { for (int i=0; i scores[i]) minSoFar = scores[i]; return minSoFar; } public static double calculateAverage(int[] scores) { int sum=0; for (int i=0; iarr[j]) { // then SWAP int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // end if } // end inner loop for j } // end outer loop for i } // end method } /** Lab: write a method to find duplicates in an UNSORTED array. * you can either write 3 versions the way we did with linear search * (return true/false, return a count, return an index) * or you can choose one way. * * (Recall: last class we did a lab on finding duplicates in a * SORTED array. ****/