Home>

Hello everyone, I ran into a problem that I described all the methods in the classes in the final test classMainI ask for the output of the results from the classAction, but unfortunately it doesn't output anything.

Please help me understand what my mistake is? I myself think that the whole problem is in the Action class, but I didn't find it exactly where.

Thanks in advance!

Here is the code itself:

Test package, class Main

package test;
import action.Action;
import factory.Factory;
public class Main {
public static void main (String [] args) {
    String [] str= new String [1];
    Factory.symbols (str);
    String regex= "\\ b \\ w * (\\ w) \\ 1 \\ w * \\ b";
    System.out.println ("1) Use a regular expression to remove all words from the sentence containing two identical consecutive letters");
    for (String s: str) {
        StringBuffer sb= new StringBuffer (s);
        Action.symbolsMatches (regex, sb);
    }
    Factory.tender (str);
    System.out.println ("2) Calculate the sums of the character codes of tokens in the entered sentence and check if the resulting number series is a non-increasing sequence.");
    Action.codesSum ();
}
}

Action Package, Action class

package action;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Action {
static public void symbolsMatches (String regex, StringBuffer symbols) {
    Pattern pattern= Pattern.compile (regex);
    Matcher matcher= pattern.matcher (symbols);
    while (matcher.find ()) {
        System.out.println (symbols.toString (). ReplaceAll (regex, "") + matcher.group ());
        }
}
static public void codesSum () {
    String tender= "";
    String [] words= tender.split ("");
    int prevSum= -1;
    for (String word: words) {
       int sum= 0;
       for (char ch: word.toCharArray ()) {
           sum += (int) ch;
        }
    if (prevSum!= -1) {
        if (prevSum <
 sum) {
            return;
        }
    prevSum= sum;
    }
System.out.println (tender);
        }
}
}

Package interface, interface IF

package interfaces;
public interface IF {
String symbols []= {"Currently there is a restriction on checks for unregistered users"
};
String tender []= {"admin coming home"};
}

Factory package, Factory class

package factory;
import interfaces.IF;
public class Factory implements IF {
    static public void symbols (String str []) {
        for (int i= 0; i <
 symbols.length; i ++) {
            for (int j= 0; j <
 str.length; j ++) {
                str [i]= symbols [i];
            }
        }
    }
    static public void tender (String str []) {
        for (int i= 0; i <
 tender.length; i ++) {
            for (int j= 0; j <
 str.length; j ++) {
                str [i]= tender [i];
            }
        }
    }
}

the regular expression does not work for you. but if I were you, I would have forgotten about it and tried to study common truths, because I have probably never seen such an incredibly complex code in my life (and I worked with Indians and Africans!). Have you ever heard of the kiss principle? so here you have antikiss. you don't know what an interface is, you don't understand what a factory is. Why do you need a regular season now? study more useful material

Дмитрий2021-11-25 18:39:11

@Dmitry yes, I would gladly study what I need, but the educational program is like this, we have an initial study of Java, and we are already pushing regular expressions and a factory ... I will definitely study common truths, but still the code needs to be completed ... Can you please point out my mistakes, just the interface and factory should work, the teacher told me so, and the regular season should work out its own ... I checked on 101regex

fallwe2021-11-25 18:39:11

Yes, and I know that this code can be reduced significantly, but for now I am doing what they say. So this is how I can make it work, I just have quarrels from the very study from Main (

fallwe2021-11-25 18:39:11

@Dmitry, is it possible that one of the problems is in the Cyrillic alphabet? P.S. There is also such a regular, if, after all, it's about it, (\ w) \ 1, it checks two identical following characters, but in the task I need to completely divide the word, which just can consist of these characters ...

fallwe2021-11-25 18:39:11

@ Dmitry is also here \ b \ w * (\ w) \ 1 \ w * \ b, but in the compiler itself this entry displays an error: Invalid escape sequence (only \ b \ t \ n \ f \ r \ " \ '\\).

fallwe2021-11-25 18:39:11