Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String regex = "\\%([A-Z][a-z]+)\\%([^|$%.])*?<(\\w+)>([^|$%.])*?\\|(\\d+)\\|([^|$%.])*?(\\d+\\.?\\d*)\\$";
- Pattern pattern = Pattern.compile(regex);
- double totalPrice = 0.0;
- double totalIncome = 0.0;
- while (!input.equals("end of shift")) {
- Matcher matcher = pattern.matcher(input);
- while (matcher.find()) {
- totalPrice = Integer.parseInt(matcher.group(5)) * Double.parseDouble(matcher.group(7));
- totalIncome += totalPrice;
- System.out.printf("%s: %s - %.2f%n",
- matcher.group(1), matcher.group(3), totalPrice);
- }
- input = scanner.nextLine();
- }
- System.out.printf("Total income: %.2f", totalIncome);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement