Created
November 27, 2018 16:14
-
-
Save CompSciRocks/a96b11cd3335712e775184dcc0794a4c to your computer and use it in GitHub Desktop.
Solution for Code Word Checker free response on the 2018 AP Computer Science Exam. https://compsci.rocks/codeword-checker-solution/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CodeWordChecker implements StringChecker { | |
private int min; | |
private int max; | |
private String no; | |
public CodeWordChecker(int mi, int ma, String n) { | |
min = mi; | |
max = ma; | |
no = n; | |
} | |
public CodeWordChecker(String n) { | |
this(6, 20, n); | |
} | |
public boolean isValid(String str) { | |
return str.length() >= min && str.length() <= max && str.indexOf(no) == -1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface StringChecker { | |
/** Returns true if str is valid */ | |
public boolean isValid(String str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment