Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- //LinkedHashMap<String, Double> linkedHashMap = new LinkedHashMap<>();
- List<String> list = new ArrayList<>();
- double total = 0.00;
- String command;
- while (!"Purchase".equals(command = sc.nextLine())) {
- Pattern regex = Pattern.compile(">>([A-Za-z\\s]+)<<(\\d+\\.?\\d+)!(\\d+)");
- //Pattern regex = Pattern.compile("([A-Za-z\\s]+)<<(\\d+(.\\d+)?)!(\\d+)");
- Matcher matcher = regex.matcher(command);
- if (matcher.find()) {
- String furniture = matcher.group(1);
- double price = Double.parseDouble(matcher.group(2));
- int quantity = Integer.parseInt(matcher.group(3));
- // if(linkedHashMap.containsKey(furniture)){
- // linkedHashMap.put(furniture, linkedHashMap.get(furniture)+(price * quantity));
- // }
- // linkedHashMap.putIfAbsent(furniture, price * quantity);
- list.add(furniture);
- total += quantity * price;
- }
- }
- //double totalSum;
- System.out.println("Bought furniture:");
- //linkedHashMap.forEach((key, value) -> System.out.printf("%s%n", key));
- // totalSum = linkedHashMap.values().stream().mapToDouble(e -> e).sum();
- // System.out.printf("Total money spend: %.2f", totalSum);
- list.stream().forEach(e-> System.out.printf("%s%n", e));
- System.out.printf("Total money spend: %.2f", total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement