2008 Checker

<< 2008 OpossumCritter | APQuestionsTrailIndex | 2007SelfDivisor >>

Question from College Board

Checker


/**
 * This is based on Question 4 of the 2008 APCS A exam.
 * 
 * @author Chris Thiel, OFMCap 
 * @version 8 May 2008
 */

public interface Checker
{
	/**
	 * @param  text	a string to consider for acceptance
	 * @return true if this Checker accepts text, false otherwise
	 */
	boolean accept(String text);
}

CheckerDriver



/**
 * Tests out your implementations
 * @author Chris Thiel
 * @version 8 May 2008
 */
public class CheckerDriver
{

    public static void main(String[] args)
    {
        Checker broccoliChecker= new SubstringChecker("broccoli");

        System.out.println("Part (a) Test:");
        System.out.println("broccoliChecker.accept(\"broccoli\"):"+broccoliChecker.accept("broccoli"));
        System.out.println("broccoliChecker.accept(\"I like broccoli\"):"+broccoliChecker.accept("I like broccoli"));
        System.out.println("broccoliChecker.accept(\"carrots are great\"):"+broccoliChecker.accept("carrots are great"));
        System.out.println("broccoliChecker.accept(\"Broccoli Bonanza\"):"+broccoliChecker.accept("Broccoli Bonanza"));

        System.out.println("Part (b) Test:");
        Checker bChecker = new SubstringChecker("beets");
        Checker cChecker = new SubstringChecker("carrots");
        Checker bothChecker = new AndChecker(bChecker, cChecker);
        Checker aChecker = new SubstringChecker("artichokes");
        Checker veggies = new AndChecker(bothChecker, aChecker);



        System.out.println("Part (c) Test:");
        Checker aChecker = new SubstringChecker("artichokes"); 
        Checker kChecker = new SubstringChecker("kale"); 
        Checker yummyChecker; 

        /* code to construct for part (c) */

        System.out.println("yummyChecker.accept(\"chocolate truffles\")"+yummyChecker.accept("chocolate truffles"));
        System.out.println("yummyChecker.accept(\"kale is great\")"+yummyChecker.accept("kale is great"));
        System.out.println("yummyChecker.accept(\"Yuck: artichokes & kale\")"+yummyChecker.accept("Yuck: artichokes & kale"));



    }
}

SubstringChecker (part a)

public class SubstringChecker impliments Checker
{

}

AndChecker (part b)

public class AndChecker implements Checker
{

}

NotChecker.java


public class NotChecker implements Checker
{


	/*
	 * returns true if and only if its Checker object 
	 * does NOT accept the  string 
	 */

}