Calculating salaries

  • 12
  • Locked
The first parameter of the main method is a file name. Each line of the specified file has the following format: name value where [name] is a String and [value] is a double. [name] and [value] are separated by a space. Find the sum of all the values for each name. Display all the data, sorted by na
You can't complete this task, because you're not signed in.
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Олег Байбула
Level 32 , Ukraine
Expert
5 March, 07:12
It's awkward using Double here instead of BigDecimal. Consider the next example if you don't agree:
Peterson 2
Smith 6
Smith 6
Smith 6
Smith 6
Baxter 1.35
Peterson 2.1
Peterson 2.1
Peterson 2.1
Justin Smith
Level 39 , Greenfield, USA, United States
7 November 2021, 13:09
CodeGym hasn't formally introduced TreeMap in the lessons yet, but it makes this rather easy. You should be familiar with it at this point, and if not I recommend googling how it works. It's just like HashMap but auto-sorts by key.
Олег Байбула
Level 32 , Ukraine
Expert
5 March, 05:13
And you should use Stream API.
Trevor
Level 23 , Phoenix, United States
31 January 2020, 20:12
Use a TreeSet and pass a comparator to sort your values :)
Henrique
Level 41 , São Paulo, Brazil
1 July 2020, 17:34
Using your idea of a TreeSet, I used a TreeMap and it worked as well (with no need of a comparator).