0% found this document useful (0 votes)
72 views

2018 CodeWordChecker - Teacher Notes

- The StringChecker class was changed from an interface to a class for the 2020 AP CS A curriculum changes - The StringChecker class now has a constructor that takes minimum and maximum string length parameters and stores them as private instance variables - The isValid method was moved from CodeWordChecker to StringChecker and returns true if the string is between the minimum and maximum lengths - When coding CodeWordChecker, students must call StringChecker's isValid method to validate the string length rather than reimplementing this check

Uploaded by

Prasham Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

2018 CodeWordChecker - Teacher Notes

- The StringChecker class was changed from an interface to a class for the 2020 AP CS A curriculum changes - The StringChecker class now has a constructor that takes minimum and maximum string length parameters and stores them as private instance variables - The isValid method was moved from CodeWordChecker to StringChecker and returns true if the string is between the minimum and maximum lengths - When coding CodeWordChecker, students must call StringChecker's isValid method to validate the string length rather than reimplementing this check

Uploaded by

Prasham Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Teacher Notes for 2018 StringChecker/CodeWordChecker FRQ rewrite:

In the original FRQ, StringChecker was an interface with just one method:
boolean isValid(String str). The 2020 changes to the AP CS A course removed abstract classes and
interfaces from the curriculum.

Changes:

 StringChecker changed to a class


 A constructor was added to the StringChecker class with two formal parameters, one for the minimum
string length, and one for the maximum string length.
 Private instance variables were added to store the min and max string lengths.
 The min and max String length logic was moved from the CodeWordChecker class and put into the
StringChecker class. The isValid method is no longer abstract. It returns true if the string parameter is
between the min and max string lengths, inclusive.
 There are no accessors for the private instance variables of the StringChecker class. This was an intentional
decision. When coding the CodeWordChecker class, this will force students to make a call to
StringChecker's isValid method (super.isValid(str)) to check the code word's length.

Solution:
public class CodeWordChecker extends StringChecker
{
private String exclude; // only one instance variable needed
// if students create a min and max
// they will be shadowing
// the StringChecker's instance variables

public CodeWordChecker(int min, int max, String str)


{
super(min, max); //Must call the constructor of
//StringChecker with the min and max
exclude = str;
}

public CodeWordChecker(String str)


{
super(6, 20); //Must call the StringChecker constructor
//with the default min, max values
exclude = str;
}

public boolean isValid(String str)


{
return super.isValid(str) //Must call StringChecker's isValid
&& str.indexOf(exclude) == -1; //to confirm that the length is
} //between the min and max lengths
} //inclusive. If students create
//min and max length values for
//this class, they would lose the
//rubric point for the super.isValid(exclude) call

Students should not shadow the parent class's instance variables. They need to reuse code instead of rewrite or copy existing code. This version of
the FRQ is testing code reuse. Shadowing the parent class's instance variables, in general, is a dangerous thing to do. The child's copy of the
instance variables may get out of sync with the parent's instance variables, because changes to either set will not be reflected in the other set. The
logic of isValid depends on the min and max values that were sent to the parent. Any changes to those variables should happen in the parent
class. The child class should only access and/or change those variables by way of parent methods.

You might also like