Advertisement
Guest User

Untitled

a guest
May 28th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5.  
  6. public class Ex3_Initiative {
  7. public static void main(String[] args) throws IOException {
  8. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9. Map<String, Map<Integer, String>> stations = new TreeMap<>();
  10. Map<String, String> purposes = new HashMap<>();
  11. stations.put("Hydra", new HashMap<>());
  12. stations.put("Arrow", new HashMap<>());
  13. stations.put("Flame", new HashMap<>());
  14. stations.put("Pearl", new HashMap<>());
  15. stations.put("Orchid", new HashMap<>());
  16. purposes.put("Hydra", "Zoological Research.");
  17. purposes.put("Arrow", "Development of defensive strategies, and Intelligence gathering.");
  18. purposes.put("Flame", "Communication.");
  19. purposes.put("Pearl", "Psychological Research and/or Observation.");
  20. purposes.put("Orchid", "Space-time manipulation research, disguised as a Botanical station.");
  21. String input = reader.readLine();
  22. while (!"Recruit".equals(input)) {
  23. String[] inputs = input.split(":");
  24. String name = inputs[0];
  25. int number = Integer.parseInt(inputs[1]);
  26. String station = inputs[2];
  27. if (stations.containsKey(station)) {
  28. stations.get(station).put(number, name);
  29. }
  30. input = reader.readLine();
  31. }
  32. String command = reader.readLine();
  33. if ("DHARMA Initiative".equals(command)) {
  34. stations.entrySet()
  35. .stream()
  36. .sorted((x, y) -> -Integer.compare(x.getValue().size(), y.getValue().size()))
  37. .forEach(x -> System.out.printf("The %s has %d DHARMA recruits in it.%n",
  38. x.getKey(), x.getValue().size()));
  39. } else {
  40. String station = command;
  41. if (!stations.containsKey(station)) {
  42. System.out.println("DHARMA Initiative does not have such a station!");
  43. } else {
  44. System.out.printf("The %s station: %s%n", station, purposes.get(station));
  45. if (stations.get(station).size() == 0) {
  46. System.out.println("No recruits.");
  47. } else {
  48. stations.get(station).keySet()
  49. .stream()
  50. .sorted(Comparator.reverseOrder())
  51. .forEach(id -> System.out.printf("###%s - %d%n", stations.get(station).get(id), id));
  52. }
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement