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 regex {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double income = 0.0;
- String input = scanner.nextLine();
- while (!"end of shift".equals(input)) {
- Pattern pattern = Pattern.compile("%(?<name>[A-Z][a-z]{2,})%[^|$%.]*<(?<product>\\w+)>[^|$%.]*\\|(?<count>[0-9]+)\\|[^|$%.]*?(?<price>\\d+\\.?\\d*)\\$");
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()) {
- String name = matcher.group("name");
- String product = matcher.group("product");
- int count = Integer.parseInt(matcher.group("count"));
- double price = Double.parseDouble(matcher.group("price"));
- System.out.printf("%s: %s - %.2f%n", name, product, price * count);
- income = income + price * count;
- }
- input = scanner.nextLine();
- }
- System.out.printf("Total income: %.2f", income);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement