Skip to content

Instantly share code, notes, and snippets.

@CompSciRocks
Created November 27, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CompSciRocks/a96b11cd3335712e775184dcc0794a4c to your computer and use it in GitHub Desktop.
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/
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;
}
}
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