Guest User

Untitled

a guest
Apr 29th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. public static void main(String[] args) throws IOException {
  2.  
  3.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  4.         String[] products = bf.readLine().split("\\s");
  5.         long[] quantities = Arrays.stream(bf.readLine().split(" "))
  6.                 .mapToLong(Long::parseLong)
  7.                 .toArray();
  8.  
  9.         double[] prices = Arrays.stream(bf.readLine().split("\\s"))
  10.                 .mapToDouble(Double::parseDouble)
  11.                 .toArray();
  12.  
  13.         while (true) {
  14.             String[] command = bf.readLine().split("\\s");
  15.             String productName = command[0];
  16.  
  17.             if (productName.equals("done")) {
  18.                 break;
  19.             }
  20.             long productQuantity = Long.parseLong(command[1]);
  21.  
  22.             for (int a = 0; a < products.length; a++) {
  23.                 if (productName.equals(products[a])) {
  24.  
  25.                     if (quantities.length > a && quantities[a] >= productQuantity) {
  26.                         System.out.printf("%s x %s costs %.2f%n", productName, productQuantity, productQuantity * prices[a]);
  27.                         quantities[a] -= productQuantity;
  28.                         break;
  29.                     } else {
  30.                         System.out.printf("We do not have enough %s%n", productName);
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment