Functionality is not enough!

  • 12
  • Locked
Old task: Read pairs (a number and string) from the keyboard, and then display them on the screen. New task: Read the same pairs from the keyboard and store them in a HashMap. Any empty input string signifies the end of data entry. The numbers can be repeated, but not the strings. The entered data must not be lost! Then the program should display the contents of the HashMap on the screen, each pair on a new line.
You can't complete this task, because you're not signed in.
Comments (22)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
DJ Stanhope
Level 16 , Meridian, United States
10 August 2021, 03:57
Conditions say any empty input signals the end of data entry, and yet in order to get the task to validate successfully I had to make it so it would continue collecting data if the name field was empty. Makes no sense.
remote87
Level 18 , Sofia, Bulgaria
20 January 2021, 13:23
passed with downloaded solution and with error?!
John Squirrels Website Admin at CodeGym
21 January 2021, 11:09
What task exactly do you refer to?
Gellert Varga
Level 23 , Szekesfehervar, Hungary
10 February 2021, 20:57
You got an NullPointerException in line 21, but just that line is unreadable on that screenshot. I would like to look that line:) and the whole prog.
HollyTi
Level 16 , Brno, Czech Republic
31 October 2020, 22:55
My solution failed at Req.3: In the main method, declare a HashMap variable and immediately initialize it, because it had: Map<String, Integer> map = new HashMap<>(); It passed with: HashMap<String, Integer> map = new HashMap<String, Integer>(); Lol, always did it my way, never failed before, as it wasn't a requirement :)
Je
Level 19 , Philippines
23 October 2020, 14:45
I discovered computeIfPresent in this hashmap exercise. hope you'll find it useful too.
Pavel Naumovich
Level 16 , Chippenham, United Kingdom
11 October 2020, 12:29
Hashmap keys must be unique, use string as keys and int as values, when displaying content of your hashmap , no particular order is required
George
Level 15 , United Kingdom
10 October 2020, 21:17
somehow I got the impression that the "empty input" condition had to do with exceptions since there's no null integer and I didn't want to split the one liner that was already there. Got it right on 1st try with try-catch but it seems this was irrelevant. I'm not even sure why this task was set to "Hard". It was a simple input and hashmap condition.
2 August 2020, 00:46
Output in different order doesn't count as a solution. For example,
1 Sam
1 Am
2 I
But it's not one of the requirements
Petros
Level 23 , Columbia, United States
30 July 2020, 20:52
Keys are unique, values aren't. In this problem Strings are keys and integers are values. Flew over my head so took me a while to solve this.
Lucas Hoage
Level 14 , Savannah, United States
7 June 2020, 20:27
Nothing has to be in order. Your output should look like: int string int string int string or int int string int string
Patrick Moreland
Level 27 , Kirkland, United States
15 March 2020, 03:04
I beat my head against a brick wall on this one for hours. I rewrote the entire thing three or four times, and went down many paths of trying to make it tolerant of all sorts of unexpected patterns of data entry. All of that was a waste of time. In the end, the issue had to do with an unexplained difference between how the online code entry handles String.isEmpty() vs. Intellij IDEA. I was only able to get this to pass using IntelliJ. Very frustrating.