Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class AssArrays {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, Double> map = new LinkedHashMap<>();
- Map<String, Double> testQuantity = new LinkedHashMap<>();
- String input = scanner.nextLine();
- while(!input.equals("buy")){
- String [] tokens = input.split(" ");
- String productName = tokens[0];
- Double price = Double.parseDouble(tokens[1]);
- Double quantity = Double.parseDouble(tokens[2]);
- Double sum = price*quantity;
- if(!map.containsKey(productName)){
- map.put(productName,sum);
- }
- else{
- double sumQauntity = testQuantity.get(productName) + quantity;
- sum = sumQauntity * price;
- map.put(productName,sum);
- }
- Double currentQuantity = quantity;
- testQuantity.put(productName,currentQuantity);
- input = scanner.nextLine();
- }
- map
- .forEach((key,value) -> System.out.printf("%s -> %.2f%n",key,value));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement