package vs; import java.util.HashMap; import java.util.Map; import java.util.Set; public class BallotBox { private Map votes = new HashMap<>(); public synchronized void vote(String choice) { Integer votes = this.votes.get(choice); if (votes == null) { votes = 0; } this.votes.put(choice, votes + 1); } public synchronized int countVotes() { int sum = 0; for (Map.Entry choice : this.votes.entrySet()) { sum += choice.getValue(); } return sum; } public synchronized int getNumberOfVotes(String choice) { Integer votes = this.votes.get(choice); if (votes == null) { votes = 0; } return votes; } public synchronized Set getChoices() { return this.votes.keySet(); } }