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;
    }
}

See Class writing order for a technique to respond to AP CS FR that request an entire class.

2018 AP CS Exam Free Response Solutions

Additional classes & objects resources

Help & comments

Get help from AP CS Tutor Brandon Horn

Comment on CodeWordChecker