Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new project, Assignment #4. Create a new package, myarrays. In the package, myarrays, create a new class, ArrayExamples. Create a new package, utils.

  1. Create a new project, Assignment #4.
  2. Create a new package, myarrays. In the package, myarrays, create a new class, ArrayExamples.
  3. Create a new package, utils. Copy the newest version of MyUtils.java, from Canvas, cosc 2425, in assignment #4's folder, place it into the utils package (it has new methods in it that are used in the test method so be sure to get this copy of MyUtils.)
  4. Create a new package, test. In the test package, create a new JUnit test case named Asg4Test. And be sure to say yes when Eclipse asks about adding JUnit5 to your build path. Copy from COSC 2425, asg4's folder on Canvas, Asg4Test.java. Open Asg4Test.java in the text editor (Atom or something similar). Copy the contents of the test - Paste the contents over the JUnit test case in Eclipse that was just created. Run the test case (File--> Run As --> JUnit Test) capture the output.

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

 
  1. // 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);
  2. // 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);
  3. // 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);
  4. //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);
  5. // 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);
  6. // 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);
  7. // 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);
  8. // 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);
  9. // 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)
  10. // 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)
  11. // 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Is conflict always unhealthy? Why or why not? (Objective 4)

Answered: 1 week ago