Advertisement
damesova

Chore Wars [Mimi]

Apr 15th, 2019
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class _03_ChoreWars {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String dishes = "<([a-z0-9]+)>";
  10.         String cleaning = "\\[([A-Z0-9]+)]";
  11.         String laundry = "\\{(.+)}";
  12.  
  13.         Pattern pDishes = Pattern.compile(dishes);
  14.         Pattern pCleaning = Pattern.compile(cleaning);
  15.         Pattern pLaundry = Pattern.compile(laundry);
  16.  
  17.         String input = "";
  18.         int countDish = 0;
  19.         int countClean = 0;
  20.         int countLaundry = 0;
  21.         while (!"wife is happy".equals(input = scanner.nextLine())) {
  22.             Matcher mDishes = pDishes.matcher(input);
  23.             Matcher mCleaning = pCleaning.matcher(input);
  24.             Matcher mLaundry = pLaundry.matcher(input);
  25.  
  26.             if(mDishes.find()){
  27.                 String dishesCounting = mDishes.group(1);
  28.  
  29.                 for (int i = 0; i < dishesCounting.length(); i++) {
  30.                     if(Character.isDigit(dishesCounting.charAt(i))){
  31.                         String one = "" + dishesCounting.charAt(i);
  32.                         countDish += Integer.parseInt(one);
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             if (mCleaning.find()){
  38.                 String cleanCounting = mCleaning.group(1);
  39.  
  40.                 for (int i = 0; i < cleanCounting.length(); i++) {
  41.                     if(Character.isDigit(cleanCounting.charAt(i))){
  42.                         String two = "" + cleanCounting.charAt(i);
  43.                         countClean += Integer.parseInt(two);
  44.                     }
  45.                 }
  46.             }
  47.  
  48.             if (mLaundry.find()){
  49.                 String laundryCounting = mLaundry.group(1);
  50.                 for (int i = 0; i < laundryCounting.length(); i++) {
  51.                     if(Character.isDigit(laundryCounting.charAt(i))){
  52.                         String three = "" + laundryCounting.charAt(i);
  53.                         countLaundry += Integer.parseInt(three);
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.  
  59.  
  60.         System.out.println("Doing the dishes - " + countDish + " min.");
  61.         System.out.println("Cleaning the house - " + countClean + " min.");
  62.         System.out.println("Doing the laundry - " + countLaundry + " min.");
  63.         System.out.println("Total - " + (countDish + countClean + countLaundry) + " min.");
  64.  
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement