Advertisement
damesova

Vapor Winter Sale [Mimi]

Mar 29th, 2019
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package OLD_FINAL_EXAM_20_12_18;
  2.  
  3. import java.util.*;
  4.  
  5. public class _01_VaporWinterSale {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String[] input = scanner.nextLine().split(", ");
  9.  
  10.         Map<String, Double> mapPrice = new HashMap<>();    
  11.         Map<String, Double> mapPriceDLC = new HashMap<>();  
  12.  
  13.         for (String s : input) {
  14.             if (s.contains("-")) {
  15.                 String[] game = s.split("-");
  16.                 String name = game[0];
  17.                 double price = Double.parseDouble(game[1]);
  18.  
  19.                 mapPrice.putIfAbsent(name, price);
  20.  
  21.  
  22.             } else if (s.contains(":")) {
  23.                 String[] game = s.split(":");
  24.                 String name = game[0];
  25.                 String dlc = game[1];
  26.                 if (mapPrice.containsKey(name)) {
  27.                     mapPriceDLC.putIfAbsent(name + " - " + dlc, null);
  28.                     mapPriceDLC.put(name + " - " + dlc, mapPrice.get(name) * 1.2);
  29.  
  30.                     mapPrice.remove(name);
  31.                 }
  32.             }
  33.         }
  34.  
  35.         mapPriceDLC.entrySet()
  36.                 .stream()
  37.                 .sorted(Comparator.comparingDouble(Map.Entry::getValue))
  38.                 .forEach(e -> {
  39.                     mapPriceDLC.put(e.getKey(), e.getValue() * 0.5);
  40.                     System.out.printf("%s - %.2f%n", e.getKey(), e.getValue());
  41.                 });
  42.  
  43.         mapPrice.entrySet()
  44.                 .stream()
  45.                 .sorted(Map.Entry.<String, Double>comparingByValue().reversed())
  46.                 .forEach(e -> {
  47.                     mapPrice.put(e.getKey(), e.getValue() * 0.8);
  48.                     System.out.printf("%s - %.2f%n", e.getKey(), e.getValue());
  49.                 });
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement