Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

4. Label problematic uses of language and their remedies

Answered: 1 week ago