CodeWordChecker free response problem from the 2018 AP Computer Science A Exam.
CodeWordChecker is #3 from the from the 2018 AP Computer Science A Free Response problems.
https://secure-media.collegeboard.org/ap/pdf/ap18-frq-computer-science-a.pdf
CodeWordChecker class
public class CodeWordChecker implements StringChecker { private int minLength; private int maxLength; private String notIn; public CodeWordChecker(int minLength, int maxLength, String notIn) { this.minLength = minLength; this.maxLength = maxLength; this.notIn = notIn; } public CodeWordChecker(String notIn) { this.minLength = 6; this.maxLength = 20; this.notIn = notIn; } public boolean isValid(String str) { return str.length() >= minLength && str.length() <= maxLength && str.indexOf(notIn) == -1; } }
possible code for other 1 param constructor