Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java method called intersectingHobbies that takes a hobby and a map with keys that are TA names and values that are a list

Write a Java method called intersectingHobbies that takes a hobby and a map with keys that are TA names and values that are a list of favorite hobbies for that TA and that returns a set that contains all the hobbies of the TAs that like the given hobby. The hobby map uses TA names as keys (strings) and has sets of hobby names as values (also strings).

For example, a variable called hobbies might contain the following map:

{Leah=[reading, hiking], Rinav=[running, piano, reading], Melody=[music, cooking, knitting]}

This map indicates that Leah likes reading and hiking and that Rinav likes running, piano, and reading, etc. If the following call is made:

Set result = intersectingHobbies("reading", hobbies)

then the variable result would be set to the following set:

[hiking, piano, reading, running]

Notice that the method returns a set containing all the hobbies liked by TAs who like reading. In the example above, Leah and Rinav like reading. Therefore, the method returns a set containing all of the hobbies those TAs like, including reading itself.

Another way of thinking about what this method is doing is that each time it encounters a TA that likes the target hobby, it includes all of the hobbies that TA likes in the overall answer.

The set returned by the method should be ordered alphabetically. If no TA likes the given hobby, the method should return an empty set.

You may assume that the given string and map are not null and none of the map's keys or values are null or reference null elements. The method should not modify the provided map or any of the structures it references. Note that you are limited to the methods provided on the cheat sheet.

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago