Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Orders {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Double> products = new TreeMap<>();
- Map<String, Integer> secondProducts = new HashMap<>();
- String line = scanner.nextLine();
- while(!line.contains("buy")){
- String[] tokens = line.split("\\s+");
- String name = tokens[0];
- Double price = Double.parseDouble(tokens[1]);
- int quantities = Integer.parseInt(tokens[2]);
- if(!products.containsKey(name)){
- products.put(name, price);
- }else{
- products.put(name, products.get(name)+ price);
- }
- if(!secondProducts.containsKey(name)){
- secondProducts.put(name, quantities);
- }else{
- secondProducts.put(name, secondProducts.get(name)+ quantities);
- }
- line = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement