Question: Implement the method countInitial which accepts as parameters an ArrayList of Strings and a letter, stored in a String. (Precondition: the String letter has only

Implement the method countInitial which accepts as parameters an ArrayList of Strings and a letter, stored in a String. (Precondition: the String letter has only one character. You do not need to check for this.) The method should return the number of Strings in the input ArrayList that start with the given letter. Your implementation should ignore the case of the Strings in the ArrayList.

Hint - the algorithm to implement this method is just a modified version of the linear search algorithm.

--------------------------------------------------------------------------------------------

This is what I have so far:

public class U7_L4_Activity_One{ public static int countInitial(ArrayList list, String letter){

int count = 0; for(String s : list) { if(letter.equals(s.substring(0,1))) { count++; } } return count; } }

--------------------------------------------------------------------------------------------

When I run my code, I get the following error:

DESCRIPTION This test case checks that your findInitial method returns the correct value when the letter parameter may or may not match the case of the word initials.

MESSAGE Make sure that you use the correct string methods to generate Strings from both letter and the ArrayList contents which will match on case.

Please help me fix my code! Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!