Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exam1;
- public class WordFilter {
- private String word;
- public WordFilter(String word) {
- this.word = word;
- }
- public boolean detect(String message) {
- if (message == null) {
- throw new IllegalArgumentException();
- }
- if (word == null || word.isEmpty()) {
- return false;
- }
- String[] arrayOfString = message.split(":");
- if (arrayOfString.length != 2){
- throw new IllegalArgumentException();
- }
- if (arrayOfString[1].indexOf(this.word) >= 0) {
- return true;
- }
- return false;
- }
- public String censor(String message) {
- if (detect(message)) {
- return message.replace(word, "<censored>");
- }
- return message;
- }
- }
Add Comment
Please, Sign In to add comment