Если есть ответ. можно не объяснять, мне просто нужен пример который не будет работать, спасибо)
package com.javarush.task.task19.task1920;
/*
Считаем зарплаты
*/
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader file = new BufferedReader(new FileReader(args[0]));
StringBuilder sb = new StringBuilder();
ArrayList<String> names = new ArrayList<>();
ArrayList<Double> salaries = new ArrayList<>();
HashMap<String, Double> table = new HashMap<>();
while (file.ready()) {
sb.append(file.readLine());
}
Pattern pattern = Pattern.compile("[a-zA-zа-яА-Я]+", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(sb.toString());
while (matcher.find()) {
names.add(matcher.group());
}
pattern = Pattern.compile("-*[0-9]+(\\.[0-9]+)?");
matcher = pattern.matcher(sb.toString());
while (matcher.find()) {
salaries.add(Double.parseDouble(matcher.group()));
}
for (int i = 0; i < names.size(); i++) {
if (!table.containsKey(names.get(i))) {
table.put(names.get(i), salaries.get(i));
} else {
Double s = table.get(names.get(i));
table.put(names.get(i), s + salaries.get(i));
}
}
List<Map.Entry<String,Double>> list = new LinkedList<Map.Entry<String, Double>>(table.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
@Override
public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
boolean chk = true;
Double s = 0.0;
for (Map.Entry<String, Double> pair: list) {
if(chk == true){
s=pair.getValue();
chk=false;
}
if(pair.getValue()==(double)s){
System.out.println(pair.getKey());
}
}
file.close();
}
}