SHARE
TWEET

Untitled

a guest Mar 17th, 2019 253 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.LinkedHashMap;
  5.  
  6. public class kur {
  7.     public static void main(String[] args) throws IOException {
  8.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9.  
  10.         LinkedHashMap<String, Double> orders = new LinkedHashMap<>();
  11.         LinkedHashMap<String, Integer> rememberProducts = new LinkedHashMap<>();
  12.  
  13.         String input = "";
  14.         while(!"buy".equals( input = reader.readLine())){
  15.  
  16.             String[] data = input.split("\\s+");
  17.  
  18.             String product = data[0];
  19.             double price = Double.parseDouble(data[1]);
  20.             int quantity = Integer.parseInt(data[2]);
  21.  
  22.             if(!orders.containsKey(product)){
  23.                 orders.put(product,quantity*price);
  24.                 rememberProducts.put(product, quantity);
  25.  
  26.             }else {
  27.                 rememberProducts.put(product, rememberProducts.get(product) + quantity);
  28.                 orders.put(product, rememberProducts.get(product) * price);
  29.             }
  30.  
  31.         }
  32.  
  33.         orders.forEach((key, value) ->
  34.                 System.out.println(String.format("%s -> %.2f", key, value)));
  35.  
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top