package com.codegym.task.task19.task1919;
/*
Calculating salaries
*/
import java.util.*;
import java.io.*; // T1919
public class Solution {
public static void main(String[] args) throws Exception {
// args = new String[] { "/uploads/teszt.txt", "blabla" };
// System.out.println(args[0] + ", " + args[1]);
ArrayList<String> fileLines = new ArrayList<>();
BufferedReader bfr = new BufferedReader(new FileReader(args[0]));
String s;
while ((s = bfr.readLine()) != null) {
if (s.isEmpty()) break;
fileLines.add(s);
}
bfr.close();
HashMap<String, Double> hshm = new HashMap<>();
String key = null;
Double d = null;
for (int i=0; i<fileLines.size(); i++) {
key = fileLines.get(i).substring(0, fileLines.get(i).indexOf(" "));
// System.out.print(key);
d = Double.parseDouble(fileLines.get(i).substring(fileLines.get(i).indexOf(" ")+1));
// System.out.println(d);
if (!hshm.containsKey(key)) {
hshm.put(key, d);
}
else hshm.put(key, hshm.get(key)+d);
}
// System.out.println(hshm);
HashMap<Double,String> hshmInverted = new HashMap<>();
for (Map.Entry<String, Double> pair : hshm.entrySet()) {
hshmInverted.put(pair.getValue(), pair.getKey());
}
// System.out.println(hshmInverted);
ArrayList<Double> dbList = new ArrayList<>(hshmInverted.keySet());
Collections.sort(dbList);
for(int i=0; i<dbList.size(); i++) {
System.out.print(hshmInverted.get(dbList.get(i))+" ");
System.out.println(dbList.get(i));
}
}
}
Should they be sorted alphabetically or in ascending order of salaries??
Resolved
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Lisa
10 October 2021, 15:18useful
That's what they write: Display all the data, sorted by name in ascending order.
I've implemented it that way and it validated.
Bye bye dear colleague, yeah, yeah 😜🤪
Ahhh.. I didn't want to do it by I can not resist...
what if the two persons have the same summed up values, young padawan?
I must be crazy, ahhh, really crazy, crazy... why do I do that... 🤪😜
+5