Advertisement
deyanmalinov

04. Orders

Mar 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.         public static void main(String[] args) {
  9.             Scanner scan = new Scanner(System.in);
  10.             Map<String, Double> fmap = new LinkedHashMap<>();
  11.             Map<String, Integer> smap = new LinkedHashMap<>();
  12.             String line = "";
  13.             while (!"buy".equals(line = scan.nextLine())){
  14.                 String[] comand = line.split(" ");
  15.                 String product = comand[0];
  16.                 double price  = Double.parseDouble(comand[1]);
  17.                 int amaunt = Integer.parseInt(comand[2]);
  18.  
  19.                 if (!fmap.containsKey(product)){
  20.                     fmap.put(product, amaunt*price);
  21.                     smap.put(product, amaunt);
  22.                 }else {
  23.  
  24.                     smap.put(product, smap.get(product)+amaunt);
  25.                     fmap.put(product, smap.get(product)*price);
  26.                 }
  27.             }
  28.            fmap.forEach((key, value) -> System.out.println(String.format("%s -> %.2f", key, value)));
  29.  
  30.         }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement