Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create the TestArrayMethods class to test the methods in ArrayMethods.java. In t

ID: 3631597 • Letter: C

Question

Create the TestArrayMethods class to test the methods in ArrayMethods.java. In this file, you should:

Create an array of char with 100 items
Initialize your array with initArray
Print the array on the screen
Find and print for each letter how many times it appears in the array (use countLetters).


ArrayMethods.java:

public class ArrayMethods
{
public static void initArray(char[] array)
{
// for each element in the array
for(int i = 0; i < array.length; i++)
// give it a random letter, A through E
array[i] = (char)('A'+(int)(Math.random()*('E'-'A'+1)));
}

public static int countLetters(char[] array, char letter)
{
int count = 0;
// look through array for letter
for(char c : array)
if(c == letter)
count++;
return count;
}
}

Explanation / Answer

public class TestArrayMethods {public static void main(String[] args) {char[] array=new char[100]; int i; char c; ArrayMethods.initArray(array); System.out.println("The characters"); for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote