rarestAge Language/Type: Related Links: Write a method named rarestAge that accepts as a parameter a to their ages (integers), and returns the least frequently occurring age containing the following key/value pairs: Java Map collections HashMap Math Char-45 Dan-15 Torry-22 Kanow 10 Toff-10 Elmc

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Java
rarest Age
Language/Type:
Related Links:
Java Map collections
HashMap Math
Write a method named rarestAge that accepts as a parameter a HashMap from students' names (strings)
to their ages (integers), and returns the least frequently occurring age. Consider a map variable named m
containing the following key/value pairs:
{Char=45, Dan=45, Jerry=23, Kasey=10, Jeff=10, Elmer-45, Kim-10, Ryan=45, Mehran=23}
Three people are age 10 (Kasey, Jeff, and Kim), two people are age 23 (Jerry and Mehran), and four people are
age 45 (Char, Dan, Elmer, and Ryan). So a call of rarestAge (m) returns 23 because only two people are that
age.
If there is a tie (two or more rarest ages that occur the same number of times), return the youngest age
among them. For example, if we added another pair of Steve-23 to the map above, there would now be a tie
of three people of age 10 (Kasey, Jeff, Kim) and three people of age 23 (Jerry, Mehran, Steve). So a call of
rarest Age (m) would now return 10 because 10 is the smaller of the rarest values. This implies that if every
person in the map has a unique age, your method would return the smallest of all the ages in the map.
If the map passed to your method is null or empty, your method should return Ø. You may assume that no
key or value stored in the map is null. Otherwise you should not make any assumptions about the number of
key/value pairs in the map or the range of possible ages that could be in the map.
Constraints: You may create one collection of your choice as auxiliary storage to solve this problem. You can
have as many simple variables as you like. You should not modify the contents of the map passed to your
method.
Java solution code goes here
Method: Write a Java method as described, not a complete program or class.
Transcribed Image Text:rarest Age Language/Type: Related Links: Java Map collections HashMap Math Write a method named rarestAge that accepts as a parameter a HashMap from students' names (strings) to their ages (integers), and returns the least frequently occurring age. Consider a map variable named m containing the following key/value pairs: {Char=45, Dan=45, Jerry=23, Kasey=10, Jeff=10, Elmer-45, Kim-10, Ryan=45, Mehran=23} Three people are age 10 (Kasey, Jeff, and Kim), two people are age 23 (Jerry and Mehran), and four people are age 45 (Char, Dan, Elmer, and Ryan). So a call of rarestAge (m) returns 23 because only two people are that age. If there is a tie (two or more rarest ages that occur the same number of times), return the youngest age among them. For example, if we added another pair of Steve-23 to the map above, there would now be a tie of three people of age 10 (Kasey, Jeff, Kim) and three people of age 23 (Jerry, Mehran, Steve). So a call of rarest Age (m) would now return 10 because 10 is the smaller of the rarest values. This implies that if every person in the map has a unique age, your method would return the smallest of all the ages in the map. If the map passed to your method is null or empty, your method should return Ø. You may assume that no key or value stored in the map is null. Otherwise you should not make any assumptions about the number of key/value pairs in the map or the range of possible ages that could be in the map. Constraints: You may create one collection of your choice as auxiliary storage to solve this problem. You can have as many simple variables as you like. You should not modify the contents of the map passed to your method. Java solution code goes here Method: Write a Java method as described, not a complete program or class.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education