emodev

Untitled

Dec 10th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package fund01July2018Part2;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class SoftuniBarIncome {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.         Pattern pattern = Pattern.compile("%([A-z][a-z]+)%.*<(\\w+).*>\\w*\\|(\\d+)\\|[a-z]*(\\d+.*\\d+)\\$");
  14.         double totalIncome = 0.0;
  15.         while (true) {
  16.             String input = reader.readLine();
  17.             if (input.equals("end of shift")) {
  18.                 break;
  19.             }
  20.             String name = "";
  21.             String product = "";
  22.             int count = 0;
  23.             double price = 0.0;
  24.  
  25.             Matcher match = pattern.matcher(input);
  26.             if (match.find()) {
  27.                 name = match.group(1);
  28.                 product = match.group(2);
  29.                 count = Integer.parseInt(match.group(3));
  30.                 price = Double.parseDouble(match.group(4));
  31.                 double sum = count * price;
  32.                 System.out.printf("%s: %s - %.2f%n", name, product, sum);
  33.                 totalIncome += sum;
  34.             }
  35.             input = input.replaceAll(String.valueOf(pattern), "");
  36.             Pattern getCount = Pattern.compile("");
  37.             String debug = "";
  38.         }
  39.  
  40.         System.out.printf("Total income: %.2f", totalIncome);
  41.     }
  42. }
Add Comment
Please, Sign In to add comment