Advertisement
alexj90

Orders Ex4

Nov 13th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Orders4 {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         Map<String,Double> drinksPrice = new HashMap<>();
  11.         Map<String,Integer>drinksQuantity = new HashMap<>();
  12.         String input = scanner.nextLine();
  13.         while (!"buy".equals(input)){
  14.  
  15.             String[] tokens = input.split(" ");
  16.             String drink = tokens[0];
  17.             double price = Double.parseDouble(tokens[1]);
  18.             int quantity = Integer.parseInt(tokens[2]);
  19.             if (!drinksPrice.containsKey(drink)) {
  20.                 drinksPrice.put(drink, price);
  21.                 drinksQuantity.put(drink, quantity);
  22.             }else{
  23.                 if (drinksPrice.values().equals(price)){
  24.                     drinksQuantity.put(drink, drinksQuantity.get(drink)+quantity);
  25.                 }else {
  26.                     drinksPrice.put(drink, price);
  27.                     drinksQuantity.put(drink, drinksQuantity.get(drink)+quantity);
  28.                 }
  29.             }
  30.             input = scanner.nextLine();
  31.         }
  32.        
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement