Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. package OldFinalExamTasks;
  2.  
  3. import java.util.*;
  4.  
  5. public class VaporWinterSale {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String[] data = scanner.nextLine().split(", ");
  10.  
  11. Map<String, Double> gameBook = new LinkedHashMap<>();
  12. Map<String, Map<String, Double>> gamesWithDcl = new TreeMap<>();
  13.  
  14. for (int i = 0; i < data.length; i++) {
  15.  
  16. if (data[i].contains("-")) {
  17. String[] input = data[i].split("-");
  18. String name = input[0];
  19. double price = Double.parseDouble(input[1]);
  20. if (!gameBook.containsKey(name)) {
  21. gameBook.put(name, price);
  22. }
  23. } else {
  24. String[] input = data[i].split(":");
  25. String name = input[0];
  26. String dcl = input[1];
  27. if (gameBook.containsKey(name)) {
  28. Map<String, Double> dclGame = new LinkedHashMap<>();
  29. double gameValue = gameBook.get(name) * 1.2;
  30. dclGame.put(dcl, gameValue);
  31. gamesWithDcl.put(name, dclGame);
  32. gameBook.remove(name);
  33. }
  34. }
  35. }
  36.  
  37. for (Map.Entry<String, Map<String, Double>> stringMapEntry : gamesWithDcl.entrySet()) {
  38. String key = stringMapEntry.getKey();
  39. for (Map.Entry<String, Double> value : stringMapEntry.getValue().entrySet()) {
  40. String dcl = value.getKey();
  41. Map<String, Double> dclGame = new LinkedHashMap<>();
  42. double newValue = value.getValue() * 0.5;
  43. dclGame.put(dcl, newValue);
  44. gamesWithDcl.put(key, dclGame);
  45. System.out.printf("%s - %s - %.2f\n",key, dcl, newValue);
  46. }
  47. }
  48. for (Map.Entry<String, Double> entry : gameBook.entrySet()) {
  49. double newValue = entry.getValue() * 0.8;
  50. gameBook.put(entry.getKey(), newValue);
  51. }
  52.  
  53. gameBook.entrySet().stream().sorted((e1, e2) ->
  54. e2.getValue().compareTo(e1.getValue())
  55. ).forEach(entry -> System.out.printf("%s - %.2f\n", entry.getKey(), entry.getValue()));
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement