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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!