X1038: Count "J" Names

public class Person
{
    private String name;

    public Person(String na)
    {
        this.name = na;
    }

    public String getName()
    {
        return name;
    }
}

The following method takes in a list of Person objects and should return the number of objects who's name starts with 'J'. However, some of the values in this list may be null.

Write a loop to iterate over each Person to count if the first letter of the name (accessed by calling getName()) starts with the character 'J'. But add in a check to make sure the object is not null, so that the method does not produce null pointer exceptions.

Your Answer:

Feedback

Your feedback will appear here when you check your answer.