1 import java.util.*; 2 3 public class SmallestSection { 4 public static String smallestSection (Map sections) { 5 6 7 8 9 10 11 12 13 } public static void main(String[] args) { Map sections = new HashMap(); "AC"); sections.put("ying", sections.put("will", "AA"); sections.put("natalie", "AA"); } System.out.println(smallestSection (sections));

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

How do you do this? Java

smallestSection
Write a method smallestSection that accepts a map of student names (strings) to section names
(strings) as a parameter, and returns the name of the section with the smallest number of students.
Consider, for example, a variable called map that contains the following elements:
{ying-AC, will=AA, natalie=AA}
A call to your method should return the following string:
AC
If there are no students in the passed in map then your method should return null. If two sections
have the smallest number of students return the name of the one that comes first alphabetically.
You may assume that the map passed is not null and that none of its elements are null or empty
strings.
For full credit, obey the following restrictions in your solution. A solution that disobeys them can get
partial credit.
• You may create only up to one (1) new data structure of your choice (list, stack, queue, set,
map, etc.) as auxiliary storage. (You can have as many simple variables as you like.)
• You may not call any Collections methods.
• You should not modify the contents of the map passed to your method.
Transcribed Image Text:smallestSection Write a method smallestSection that accepts a map of student names (strings) to section names (strings) as a parameter, and returns the name of the section with the smallest number of students. Consider, for example, a variable called map that contains the following elements: {ying-AC, will=AA, natalie=AA} A call to your method should return the following string: AC If there are no students in the passed in map then your method should return null. If two sections have the smallest number of students return the name of the one that comes first alphabetically. You may assume that the map passed is not null and that none of its elements are null or empty strings. For full credit, obey the following restrictions in your solution. A solution that disobeys them can get partial credit. • You may create only up to one (1) new data structure of your choice (list, stack, queue, set, map, etc.) as auxiliary storage. (You can have as many simple variables as you like.) • You may not call any Collections methods. • You should not modify the contents of the map passed to your method.
1 import java.util.*;
2
3 public class SmallestSection {
4
public static String smallestSection (Map<String, String> sections) {
5
6
7
8
9
10
11
12 }
13}
public static void main(String[] args) {
Map<String, String> sections = new HashMap<String, String>();
sections.put("ying", "AC");
sections.put("will", "AA");
sections.put("natalie", "AA");
System.out.println(smallestSection(sections));
Transcribed Image Text:1 import java.util.*; 2 3 public class SmallestSection { 4 public static String smallestSection (Map<String, String> sections) { 5 6 7 8 9 10 11 12 } 13} public static void main(String[] args) { Map<String, String> sections = new HashMap<String, String>(); sections.put("ying", "AC"); sections.put("will", "AA"); sections.put("natalie", "AA"); System.out.println(smallestSection(sections));
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
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