Add a method (call it spotterAnimalArea) to AnimalLab that takes two parameters — animalType and areaID — and returns a String containing the IDs of spotters that have seen the animal in that particular area. You should include only spotters who reported a sighting with count greater than zero. You should exclude duplicate spotter IDs.import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Add a method (call it spotterAnimalArea) to AnimalLab that takes two parameters —
animalType and areaID — and returns a String containing the IDs of spotters that have
seen the animal in that particular area. You should include only spotters who reported a
sighting with count greater than zero. You should exclude duplicate spotter IDs.import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


 */
public class AnimalLab
{
    private ArrayList<SightingRecord> records;
    private ArrayList<String > dubID;
    
    /**
     * Create an AnimalLab.
     */
    public AnimalLab()
    {
        records = new ArrayList<>();
        addSightingRecords("records.csv");

    }
    
    /**
     * Add the sightings recorded in the given filename to the current list.
     * @param filename A CSV file of Sighting records.
     */
    private void addSightingRecords(String filename)
    {
        SightingReader reader = new SightingReader();
        records.addAll(reader.getSightings(filename));
    }
    
    /**
     * Print details of all the sightings of the given animal.
     * @param animal The type of animal.
     */
    public void printSightingsOf(String animalType)
    {
        records.stream()
                 .filter(sighting -> animalType.equals(sighting.getAnimal()))
                 .forEach(sighting -> System.out.println(sighting.getDetails()));
                
    }
    
    /**
     * Return a count of the specific animal reported in the given time period.
     * @param animal The type of animal.
     * @param timePeriod The time period.
     * @return The sum of sightings.
     */
    
    /**
     *  You should include only spotters who reported a 
sighting with count greater than zero. You should exclude duplicate spotter IDs

returns a String containing the IDs of spotters that have 
seen the animal in that particular area
     */
    public int getSightingSum(String animal, int timePeriod)
    {
       {
          
           return records.stream()
                        .filter(sighting -> animal.equals(sighting.getAnimal()))
                        .filter(sighting -> sighting.getPeriod() == timePeriod)
                        .filter(sighting -> sighting.getCount() > 0)
                        .map(sighting -> sighting.getSpotter() )
                        .reduce(0, (runningSum, count) -> runningSum + count);
           
           
           
        }
    }
        
    public String spotterAnimalArea(String animalType, int areID) 
    
    {
        
    
        return records.stream()
        .filter(sighting -> animalType.equals(sighting.getAnimal()))
        .filter(sighting -> sighting.getArea() == areID)
        .map(sighting -> (sighting.getSpotter()))
        .reduce("", (sum, b) -> sum + b);
    }
}


++++++++++++++

 

/**
 * Details of a sighting of a type of animal by an individual spotter.
 * 

public class SightingRecord 
{
    // The animal spotted.
    private final String recordedAnimal;
    // The ID of the spotter.
    private final int spotterID;
    // How many were seen.
    private final int animalCount;
    // The ID of the area in which they were seen.
    private final int areaID;
    // The reporting period.
    private final int period;
    
    /**
     * Create a record of a sighting of a particular type of animal.
     * @param animal The animal spotted.
     * @param spotter The ID of the spotter.
     * @param count How many were seen (>= 0).
     * @param area The ID of the area in which they were seen.
     * @param period The reporting period.
     */
    public SightingRecord(String animal, int spotter, int count, int area, int period)
    {
        recordedAnimal = animal;
        spotterID = spotter;
        animalCount = count;
        areaID = area;
        this.period = period;
    }

    /**
     * Return the type of animal spotted.
     * @return The animal type.
     */
    public String getAnimal() 
    {
        return recordedAnimal;
    }

    /**
     * Return the ID of the spotter.
     * @return The spotter's ID.
     */
    public int getSpotter() 
    {
        return spotterID;
    }

    /**
     * Return how many were spotted.
     * @return The number seen.
     */
    public int getCount() 
    {
        return animalCount;
    }

    /**
     * Return the ID of the area in which they were seen.
     * @return Where they were seen.
     */
    public int getArea() 
    {
        return areaID;
    }

    /**
     * Return the period in which they were seen.
     * @return When they were seen.
     */
    public int getPeriod() 
    {
        return period;
    }

    /**
     * Return a string containing details of the animal, the number seen,
     * where they were seen, who spotted them and when.
     * @return A string giving details of the sighting.
     */
    public String getDetails() 
    {
        return recordedAnimal + 
               ", count = " + animalCount + 
               ", area = " + areaID + 
               ", spotter = " + spotterID + 
               ", period = " + period;
    }   
}

JAVA

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY