Question
Write a class called TripRecords with one method called recordTrip. Trip information will be stored in a private class member variable tripMap, a map in
Write a class called TripRecords with one method called recordTrip.
Trip information will be stored in a private class member variable tripMap, a map in which the keys are names of people and the values are sets of place names. The recordTrip method will take as parameters a person's name followed by a place name and will add the data to the existing tripMap. For example, if we start with an empty map stored in a variable called trips and we make the following calls:
recordTrip("John", "London"); recordTrip("Sally", "Seattle"); recordTrip("John", "Paris"); recordTrip("Sally", "San Francisco"); recordTrip("John", "NYC"); recordTrip("John", "Paris")
the map would store the following values after these calls:
{John=[London, NYC, Paris], Sally=[San Francisco, Seattle]}
Notice that the map needs to construct a set for each person to store the names of the places they have visited. The sets it constructs should store the place names in alphabetical order.
Assume the following constructor has already been written:
public TripRecords() { tripMap = new HashMap<>(); }
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