MultPractice free response problem from the 2017 AP Computer Science A Exam.
MultPractice is #2 from the from the 2017 AP Computer Science A Free Response problems.
https://secure-media.collegeboard.org/ap/pdf/ap-computer-science-a-frq-2017.pdf
MultPractice class
This is both my time constrained and considered approach.
public class MultPractice implements StudyPractice { private final int first; private int second; public MultPractice(int f, int s) { first = f; second = s; } public String getProblem() { return first + " TIMES " + second; } public void nextProblem() { second++; } }
On the exam, for some reason I thought final was written and capitals and wrote “FINAL”. Will I lose points?
I don’t know. The College Board hasn’t released the scoring guidelines yet. The variable doesn’t actually have to be declared as
final
but having the keyword in all caps could be considered extra code with a side effect.Java constants are typically declared in all caps (though the
final
keyword is still lowercase). I used lowercase here because the field isn’t a constant in the sense that it’s initialized at declaration.I wrote my return statement like ” return first + ” ” + “TIMES” + ” ” + second; ” do you think this is still valid?
Yep. It’s a little silly but it works fine.
I didn’t put final for the first int. Will that be a point off?
Nope. The variable doesn’t have to be final.
I think I put static for both private variables. So my first variable was “private static final int first,” and my second one was “private static int second.” Will I get a point off, you think?
My guess would be that you would lose a point for incorrectly making the variables static. Static variables exist once for the entire class, not once for each instance, so if more than one
MultPractice
object was created they would share the same variables. This wouldn’t work.Is there a penalty for not using capitalization for the final variable name. like
private final int FIRST;
or
private final int first;
No.
My favorite part of this question, is that this short question is worth %12.5 percent of the exam (Given that there are 4 FRQs worth 50% of the test).
did I need to create a toString method for this problem
No. If you wrote a
toString
method and it didn’t have a side effect I doubt you would be penalized though.will I get any points off if I forgot to put private?
Historically, scoring guidelines have been pretty picky about making instance variables
private
. My guess would be that you would lose a point for it. (This is only a guess since the scoring guidelines haven’t been released yet.)