Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please solve using explanation The following code creates a Hashmap called people which stores key/age pairs. It makes a separate map for children (less than

please solve using explanation
image text in transcribed
image text in transcribed
The following code creates a Hashmap called people which stores key/age pairs. It makes a separate map for children (less than 18 years old) and prints them in order by age. The strategy is to go through each of the key/age pairs, check if age less than 18 to add that information to a new "child map" and remove it from people map. Finally, it goes through this child map in order by age and produces the desired output. Complete the five missing lines as indicated in the numbered comments. lic class JavaApplication II 1. Declare children map to be used for (String key : people.keyset()) 1 /I 2. Retrieve age corresponding to this person II 3. if a child, add it to children map if ( aget 1/ create a Hashmap object called people HashMapsstring, Integer > people = new HashMap (); 11 add keys and values (Name, Age) people, put ("John", 2); people,put ("Steve", 30); people.put ("Angie", 3); HashMapestring, Integer> children = ExtractChildren (people): 11 5. Create a sorted version of the children map called sortedChildren for (String I : sortedchildren, keyset ()) System.out.println ("key: "+ + + " value: "+ sortedchildren,get(i))

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions