Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the following general methods in a package named myarrays, and put them all in a class named ArrayExamples. BE SURE TO ADD 3 EXAMPLE
Complete the following general methods in a package named myarrays, and put them all in a class named ArrayExamples.
BE SURE TO ADD 3 EXAMPLE CALLS AND COMMENTS TO EACH METHOD
// finds and returns largest value in the array list.
// precondition: numElementsInArray >=0 and list.length >= 0
// if NumElements is 0, returns 0 as largest value.
// receives: list - an array of ints, numElementsInArray - current number of elements stored in list
// Example call #1: int theMax = ArrayExamples.findMax(someArrayOfInts, size);
// Example call #2: int biggest = ArrayExamples.findMax(myList, 10);
// Example call #3: int aMax = ArrayExamples.findMax(yourList, 25);
public static int findMax(int [] list, int numElementsInArray);
// finds and returns the smallest value in the array list.
// precondition: numElementsInArray >= 0 and list.length >= 0
// if numElements is 0, returns 0 as the smallest value.
// receives: list - an array of ints, numElementsInArray - current number of elements stored in list
// Example call #1:
// Example call #2:
// Example call #3:
public static int findMin(int [] list, int numElementsInArray);
// computes and returns average of all values in array list
// computes the average as a double
// precondition: numElementsInArray >=0 and list.length >=0
// returns 0 if numElements is 0.
// receives: list - an array of ints, numElementsInArray - current number of elements stored in list
// Example call #1:
// Example call #2:
// Example call #3:
public static double computeAverage(int [] list, int numElementsInArray);
//reverses the array elements, so first element becomes last, last becomes first etc.
// the array has numElementsInArray values stored in it currently
//
// precondition: numElementsInArray >=0 and list.length >= 0 and numElementsInArray <= list.length
// receives: list - an array of ints, numElementsInArray - current number of elements stored in list
// so if list1 has 3 values in it: 4, 15, 34, 200 list1 becomes 200, 34, 15, 4 after it is reversed
// Example call #1:
// Example call #2:
// Example call #3:
public static void reverseArray(int [] list, int numElementsInArray);
// counts the number of times the received String, valueToMatch,
// appears in the String array list, ignores case.
// returns that count. Matches case INSENSITIVE
// receives: list - an array of Strings to examine, int numElementsInArray, and the String, valueToMatch
// Example call #1:
// Example call #2:
// Example call #3:
public static int countMatches(String [] list, int numElementsInArray, String valueToMatch);
// populates received integer array with all zero values
// precondition:
// receives: array of integers that will have all locations set to zero
// Example call #1:
// Example call #2:
// Example call #3:
public static void resetArray(int [] list);
// populates received integer array with count of each letter of alphabet in received String (case-insensitive)
// size of int array is 26 exactly and is zeroed out.
// receives: String to count letters in, and an array of integers of size 26, ASSUMES that the array has all elements set to zero prior to
// this method being used
// Example : given "cats and dogs" as the String, list[0] = 2, list[1] = 0, list[2] = 1, list[3]=2 etc.
// each array location corresponds to a letter of the alphabet, 'a' is location 0, 'b' is location 1 etc.
// Example call #1:
// Example call #2:
// Example call #3:
public static void countLetters(String aString, int [] list);
// returns a String in described format of current letters in array
// receives the int array of letter counts
// Example: Assume: letterCount[1] = 4, letterCount[5] = 2,letterCount[6] = 3, with 0's all other locations returns: "[bbbbffggg]"
// Example call #1:
// Example call #2:
// Example call #3:
public static String getLetters(int []letterCount);
// Gets value in a "letterCount" array in which each index corresponds to a letter of the alphabet, case-insensitive
// so the letterCount array has 26 indexes, 0 to 25.
// receives: letterCount array and specific letter
// returns: count of corresponding letter
// if invalid (non-letter) character received, returns 0.
public static int getCount(int []countArray, char ch)
// Adds contents of 2 int arrays received, returns an array with sum of each corresponding row.
// receives: 2 integer arrays of same length which is >=0
// returns an integer array with the sum of both array values per row.
// precondition: both arrays are same length, if not returns an array of length 0
// note: here is how to create an int [] array of length 0:
// int [] retValue = new int [0];
// Example call #1:
// Example call #2:
// Example call #3:
public static int [] getArraySum(int [] array1, int []array2)
// receives: an array of String values
// returns: an array of String values with exact same values as in received array
//
// example: String [] myNames = { "Joe", "Joey","JOEY", "JOE", "Maria", "MARIA"};
// returned array contents: { "Joe", "Joey","JOEY", "JOE", "Maria", "MARIA"};
// Example call: String [] result = copyStringArray(myNames);
//
public static String [] copyStringArray(String [] array)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started