Advertisement
SensaBG

Brief Refactoring for readability

Nov 11th, 2024 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class da {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         Map<String, List<Double>> productsMap = new LinkedHashMap<>();
  8.         String[] command = scanner.nextLine().split(" ");
  9.  
  10.         while (!command[0].equals("buy")) {
  11.  
  12. // Rename -> "key" -> product
  13.             String product = command[0];
  14.  
  15.             double price = Double.parseDouble(command[1]);
  16.             double quantity = Double.parseDouble(command[2]);
  17. //( Arrays.asList(0.0, 0.0))); ) taq glupost nz kak intelij ti e q predlojil tui kato makes no sense, no moje bi si oburkal //neshto sintakti4no i za tva ti e dal thrashy suggestion, anyway mirishe mi na GPT
  18.  
  19.             productsMap.putIfAbsent(product, new ArrayList<>());
  20.             productsMap.get(product).set(0, price);
  21.  
  22. // Izvedi segashnoto kolichestvo v nova promenliva
  23.             double currentQty = productsMap.get(product).get(1);
  24.  
  25.             productsMap.get(product).set(1, currentQty + quantity);
  26.  
  27.             command = scanner.nextLine().split(" ");
  28.         }
  29.  
  30.         for (Map.Entry<String, List<Double>> pair : productsMap.entrySet()) {
  31. // Izvedi gi I tiq v promenlivi da e qsno we da go ea
  32.             String team = pair.getKey();
  33.             double price = pair.getValue().get(0);
  34.             double quantity = pair.getValue().get(1);
  35. // Overall da polzvash <List> det ti pazi kolichestvo i cena ne e ailqk
  36.             double totalPrice = price * quantity;
  37.             System.out.printf("%s -> %.2f\n", team, totalPrice);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement