Question
Suppose you want to add some more to the SleighTrack class we wrote in class: import java.util.Map ; public class SleighTrack { private Map locationCount;
Suppose you want to add some more to the SleighTrack class we wrote in class:
import java.util.Map; public class SleighTrack { private MaplocationCount; public SleighTrack(String directions) { locationCount = new HashMap (); locationCount.put(new Location(0, 0), 1); } }
public SleighTrack(String directions) { locationCount = new HashMap(); locationCount.put(new Location(0, 0), 1); int x = 0; int y = 0; for (int i = 0; i < directions.length(); i++) { if (directions.charAt(i) == '>') { x += 1; } else if (directions.charAt(i) == '<') { x -= 1; } else if (directions.charAt(i) == '^') { y += 1; } else if (directions.charAt(i) == 'v') { y -= 1; } else { throw new IllegalArgumentException(); } Location loc = new Location(x, y); int t = locationCount.getOrDefault(loc, 0); locationCount.put(loc, t+1); } }
A. Write a public boolean allVisited(Set
B. Write a public int mostPresents() method that returns the highest number of presents delivered to a single location in the current SleighTrack. (It is possible to do this one without a for loop, but youll need to read over the instance method of Map and the static methods of Collections to see how.)
C. Write a public void presentsToCoal(Set
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started