Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions