AP CSA FRQ #2 Class Design

In FRQ 2: Class Design, you are expected to write a class that meets the given specification. The question might require you to use inheritance and extend a given class.

You will be provided with a description of the class that you will have to write as well as a table that represents the use of the class and the expected result. In some cases, you will be provided with a helper class.

As always:

  • be sure that you read carefully,
  • use the highlighting tools in Blue Book,
  • consult the AP Java Quick Reference if these classes are involved.

Some more specific tips for approaching FRQ 2: Class Design are as follows:

  • Look closely as the provided table. You will gain a better understanding of constructor parameters and instance variables as well as method return types and their parameters by looking at the examples. For example, in the 2024 #2, you are given the call: Scoreboard game = new Scoreboard ("Red", "Blue"); This tells us that the constructor has two String objects as parameters. This also means that you will need to have two String instance variables. Any other data that is being stored for the object will need to be set in the constructor, but isn't coming from the user. Another example from the 2024 #2 is the call info = game.getScore(); This line tells us that we have to write a method getScore that doesn't have any parameters and has a return type of String, since info is a String variable and the Value Returned column has a String in it. The next call is game.recordPlay(1);. This line tells us we have a void method recordPlay that has a single int parameter. You can also glean the number of constructors and methods are are required.
  • You may need more instance variables than your constructor has parameters. Often, there are additional instance variable than just the constructor parameters. Let's look at 2024 #2 more closely. In reading the bulleted paragraphs, we learn that we need a way to determine which team has the current turn and we need to keep scores for both of the teams. So this class has 5 instance variables. Two String objects for the team names, a variable to determine the team currently playing, and two int variables for the score. These 3 additional variables will need initial values provided in the constructor.
  • Only write what you are required to write. You may have been trained that you need to have a multiple constructors, such as every class needs to have a default constructor. And that you should have accessor and mutator methods for all your instance variables. These are great rules for the real world, but for the AP CSA exam, please, please, please, ONLY write the constructor and methods that are required. You could lose points for doing more than you are supposed to do if it causes a unintended side effect.
  • Know the basic structure of a class. You will need to have a header, private instance variables, a constructor and methods. There is a basic formula that you can and should follow to maximize your number of points. If you forget, you should look at the other provided classes in the FRQ section. Chances are you can get some tips from those questions as well. Here is a basic outline of a class to follow:

public class ClassName {
   //instance variables
   private type name;

   //constructor
   public ClassName (type param1, type param2, ...) { 
      //body
   }

   public returnType methodName (type param1, type param2...) {
       //body
   }
}        

  • Just because you are given a class doesn't mean you are extending it. Sometimes you will be given a helper class. This class could be included because you need to create an instance variable of that type or it could be provided because you need to extend this class. The is-a test is a good one for inheritance. Let's look at an example or two. Check of 2022 FRQ #2. In this question, you are provided with a Book class and asked to write a Textbook class. Does this pass the is-a question? Would you say yes or no to the following statement? A Textbook is a Book. You would answer yes. So most likely, you need to use inheritance. And in this question, you definitely were asked to extend Book. Another clue, well they tell you: You will write a Textbook class, which is a subclass of Book. Let's look at 2021 FRQ #2. In this question you are provided a class SingleTable and asked to write the class CombinedTable. Does this pass the is-a question? Would you say yes or no to the following statement? A CombinedTable is a SingleTable. Hopefully you answered no. But this question caught many students who were advised that if you were given another class, you had inheritance. That's not true. You have to be sure that you are understanding the relationship between the classes. In this question, a CombinedTable was comprised of two SingleTable objects. This is a has-a relationship, which tells us that we need instance variables of type SingleTable. We would say yes to the statement: CombinedTable has a SingleTable.

Best of luck on your exam!

To view or add a comment, sign in

More articles by Crystal Sheldon

  • AP CSA Free Response Questions #4

    Last question!! Question #4 has students analyze and manipulate data in a 2D array. Sometimes these questions…

    1 Comment
  • AP CSA Exam FRQ #3 Tips

    The third free response question has students analyzing and manipulating data stored in array or ArrayList objects or…

  • AP CSA FRQ #1 String Version

    Sometimes you will find that FRQ #1 Methods and Control Structures involves manipulating String objects. This article…

  • AP CSA Free Response Question #1 Tips

    The first free response question, Methods and Control Structures, tests students on units 1 - 4, with a special focus…

    1 Comment
  • Tips for Preparing Students for AP CSA FRQs

    The last article was about test taking strategies for students, but how should teachers prepare their students for the…

  • AP CSA Exam Day Tips

    Attention #APCSA teachers! The exam is a little more than a month away. In this article series, I will be sharing tips…

    1 Comment
  • Local-Variable Types and AP CSA

    When I first heard of using var, I didn't quite understand why we would want to use it. After all, one of Java's…

  • Local-Variable Type

    When I first heard of using var, I didn't quite understand why we would want to use it. After all, one of Java's…

  • Conditionals Series: Switch Expressions and the AP CSA Free Response Questions

    Looking for a refresher on Switch Statements and Switch Expressions? Check out my article here. If you are an #APCSA…

  • Conditionals Series: Switch Expressions - Determining a Value

    Before we look at #SwitchExpressions, lets take a few moments to explore #SwitchStatements and the difference between…

Insights from the community

Others also viewed

Explore topics