Limited access

Upgrade to access all content for this subject

Consider the following method that returns the number of fish in the lake for a specific pollution condition (polluted sections or unpolluted sections of the lake).

// Pre-condition: lakeGrid is an ArrayList of lake sections.  Each Section identifies the GPS coordinates 
// of that section of the lake, whether the section is polluted, and the number of fish in the section.
//                isPolluted is either true or false and will be used to determine which sections of fish to count
public static int countFish(ArrayList<Section> lakeGrid, boolean isPolluted)
{
    // code not shown
}

Which of the following code segments will print the percentage of fish in the entire lake that are in the polluted sections of the lake and the percentage of all fish in the unpolluted sections of the lake? Assume that lakeGrid is assigned an array list of lake sections.

I.

    ArrayList<Section> lakeGrid = // assigned an array list of lake sections 
    double totPolluted = countFish(lakeGrid,true);
    double totNotPolluted = countFish(lakeGrid,false);
    System.out.println("% of fish in polluted sections: " + 
                       totPolluted/(totPolluted + totNotPolluted));
    System.out.println("% of fish in unpolluted sections" + 
                       totNotPolluted/(totPolluted + totNotPolluted));

II.

    ArrayList<Section> lakeGrid = // assigned an array list of lake sections 
    System.out.println("% of fish in polluted sections" + 
                      (countFish(lakeGrid,true) / countFish(lakeGrid,true) + 
                       countFish(lakeGrid,false));
    System.out.println("% of fish in unpolluted sections" + 
                       (countFish(lakeGrid,false) / countFish(lakeGrid,true) + 
                       countFish(lakeGrid,false));

III.

    ArrayList<Section> lakeGrid = // assigned an array list of lake sections 
    int totPolluted = countFish(lakeGrid,true);
    int totNotPolluted = countFish(lakeGrid,false);
    System.out.println("% of fish in polluted section" + 
                       totPolluted/(totPolluted + totNotPolluted));
    System.out.println("% of fish in unpolluted section" + 
                       totNotPolluted/(totPolluted + totNotPolluted));
A

I only.

B

II only.

C

III only.

D

I and II only.

E

I, II, and III.

Select an assignment template