dimanche 2 décembre 2018

Method with ArrayList as a parameter - Objects First with Java 6th edt

I've trying to figure out this exercise in the book Objects First with Java for a couple of hours, not managing to understand several aspects.

The exercise reads: Rewrite the printEndangered method in your project to use streams. Test. (To test this method, it may be easiest to write a test method that creates an ArrayList of animal names and calls the printEndangered method with it.)

 /**
 * Print a list of the types of animal considered to be endangered.
 * @param animalNames A list of animals names.
 * @param dangerThreshold Counts less-than or equal-to to this level
 *                        are considered to be dangerous.
 */
public void printEndangered(ArrayList<String> animalNames, 
                            int dangerThreshold)          

{
    for(String animal : animalNames) {
        if(getCount(animal) <= dangerThreshold) {
            System.out.println(animal + " is endangered.");
        }
    }
}

At the start of this chapter I was asked to test out the methods of this class, but the printEndangered-method I didn't get to work. I did not understand what to put in the parameter field of the ArrayList-parameter, and so now I can't manage to write this method.

How do you use an ArrayList as a parameter? What do they mean by write a test method that creates an ArrayList of animal names? How will I go forth writing this method?

Aucun commentaire:

Enregistrer un commentaire