11: More help for Santa

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


Suppose you want to add some more functionality to the SleighTrack class we wrote in class. Each of the following should be instance methods you add to SleighTrack:

A. (1 point) Write a public boolean notFinished(Set<Location> locations) method that returns true iff the current SleighTrack instance has not visited all of the given locations. (It is possible to do this one without using a for loop, but it’s OK if do need one. Hint: You can ask a Map for the set of its Keys.)

B. (1 point) Write a public int leastPresents() method that returns the lowest number of presents delivered to a single location in the current SleighTrack. (It is possible to do this one without a for loop, but you’ll need to read over the instance methods of Map and the static methods of Collections to see how, again, it’s fine if you do end up using a loop.)

Hint: Let map be a HashMap. You can represent map‘s values or keySet as an array by using map.values().toArray() or map.keySet().toArray() respectively. This may come in handy for getting a initial minimum value, should you choose to use a loop.

C. (1 point) Santa has been doing his research and has compiled a list of kids who have been bullying and need to be disciplined. Write a public void punishBullies(Set<Location> locations) method that removes the given locations of the bullies’ houses from the current SleighTrack, if they are in it. (It is again possible to do this one without a for loop, but you’ll need to carefully read over the instance methods of Map to see how.)