Advertisement
Zneeky

WinterSale

Aug 8th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. package finalExamPrep;
  2.  
  3. import java.util.HashMap;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7.  
  8. public class VaparWinterSale {
  9.  
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.         Map<String,Double>gamesPrice=new LinkedHashMap<>();
  13.         Map<String,String>gameWithDlC=new LinkedHashMap<>();
  14.  
  15.  
  16.         String[]input=scanner.nextLine().split(", ");
  17.         for (String game:input) {
  18.  
  19.             if (game.contains("-")){
  20.                 String[]data=game.split("-");
  21.                 String gameName=data[0];
  22.                 double price=Double.parseDouble(data[1]);
  23.  
  24.                 gamesPrice.put(gameName,price);
  25.  
  26.             }else if (game.contains(":")){
  27.                 String[]data=game.split(":");
  28.                 String gameName=data[0];
  29.                 String DLC=data[1];
  30.  
  31.                 if (gamesPrice.containsKey(gameName)){
  32.                     gameWithDlC.put(gameName,DLC);
  33.                     gamesPrice.put(gameName,gamesPrice.get(gameName)*1.2);
  34.                 }
  35.             }
  36.         }
  37.         for (Map.Entry<String, Double> entry : gamesPrice.entrySet()) {
  38.             if (gameWithDlC.containsKey(entry.getKey())){
  39.                 gamesPrice.put(entry.getKey(),entry.getValue()*0.50);
  40.             }else {
  41.                 gamesPrice.put(entry.getKey(),entry.getValue()*0.80);
  42.             }
  43.         }
  44.         gamesPrice.entrySet().stream()
  45.                 .sorted((p1,p2)-> Double.compare(p1.getValue(),p2.getValue()))
  46.                 .forEach(e->{
  47.                     if (gameWithDlC.containsKey(e.getKey())){
  48.                         System.out.println(String
  49.                                 .format("%s - %s - %.2f",e.getKey(),gameWithDlC.get(e.getKey()),e.getValue()));
  50.                     }
  51.                 });
  52.  
  53.         gamesPrice.entrySet().stream()
  54.                 .sorted((p1,p2)->Double.compare(p2.getValue(),p1.getValue()))
  55.                 .forEach(e->{
  56.                     if (!gameWithDlC.containsKey(e.getKey())){
  57.                         System.out.println(String.format("%s - %.2f",e.getKey(),e.getValue()));
  58.                     }
  59.                 });
  60.  
  61.  
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement