jwrbg

sad

Apr 11th, 2019
356
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package TechModule;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class p07_RegexSoftUniBarIncome {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         String input=scanner.nextLine();
  11.  
  12.         String regex="^%(?<name>[A-Z][a-z]*)%[\\|\\$\\%\\.]*<(?<product>[A-Za-z]+)>[\\|\\$\\%\\.]*\\|(?<count>[0-9]+)\\|[\\|\\$\\%\\.]*(?<price>[0-9]+\\.*[0-9]*)[$]$";
  13.  
  14.         Pattern patter=Pattern.compile(regex);
  15.         double sum=0;
  16.  
  17.         while(!input.equals("end of shift")){
  18.  
  19.        Matcher matcher=patter.matcher(input);
  20.        while(matcher.find()){
  21.            double a =Double.parseDouble(matcher.group("count"));
  22.            double b= Double.parseDouble(matcher.group("price"));
  23.            System.out.println(String.format("%s: %s - %.2f",matcher.group("name"),matcher.group("product"),a*b));
  24.            sum+=a*b;
  25.        }
  26.  
  27.  
  28.             input=scanner.nextLine();
  29.  
  30.  
  31.         }
  32.         System.out.println(String.format("Total income: %.2f",sum));
  33.     }
  34. }
RAW Paste Data