Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Orders4 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String,Double> drinksPrice = new HashMap<>();
- Map<String,Integer>drinksQuantity = new HashMap<>();
- String input = scanner.nextLine();
- while (!"buy".equals(input)){
- String[] tokens = input.split(" ");
- String drink = tokens[0];
- double price = Double.parseDouble(tokens[1]);
- int quantity = Integer.parseInt(tokens[2]);
- if (!drinksPrice.containsKey(drink)) {
- drinksPrice.put(drink, price);
- drinksQuantity.put(drink, quantity);
- }else{
- if (drinksPrice.values().equals(price)){
- drinksQuantity.put(drink, drinksQuantity.get(drink)+quantity);
- }else {
- drinksPrice.put(drink, price);
- drinksQuantity.put(drink, drinksQuantity.get(drink)+quantity);
- }
- }
- input = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement