*** Official AP Computer Science A Thread 2014-2015 ***

int sum = 0;

for (int i = 0; i < arr.length; i++)

  sum+=arr brackets i

return sum;

This is what i did for 1a…not sure if this is right

wont let me put brackets :blush:

Here’s my implementation of #2 (the guessing game one). Please tell me if I made any mistakes

class HiddenWord {

. . . . String word;

. . . . HiddenWord(String word) {

. . . . . . . . this.word = word;

. . . . }

. . . . String getHint(String guess) {

. . . . . . . . char[] hint = new char[guess.length()];

. . . . . . . . for (int letterIndex = 0; letterIndex < guess.length(); letterIndex++)

. . . . . . . . . . . . if (guess.charAt(letterIndex) == word.charAt(letterIndex))

. . . . . . . . . . . . . . . . hint[letterIndex] = guess.charAt(letterIndex);

. . . . . . . . . . . . else if (word.indexOf(guess.charAt(letterIndex)) == -1)

. . . . . . . . . . . . . . . . hint[letterIndex] = ‘*’;

. . . . . . . . . . . . else

. . . . . . . . . . . . . . . . hint[letterIndex] = ‘+’;

. . . . . . . . . return new String(hint);

. . . . }

}

For 4a are we supposed to do…

public interface NumberGroup

public abstract boolean contains(int num);

I am pretty sure that will be worth like 2-3 points.

@harsh98 I don’t think you need the abstract key word.

@harsh98 For interfaces, you’re only supposed to have the return type, method name and parameter.
All the methods of an interface are public static abstract (or something like that) so in your case, it should just be
boolean contains(int num);
Not sure if you’ll get docked for that.

@rdeng2614 Thanks! lol I actually implemented the method. How stupid of me!! I dont know how much points will that cost me. :frowning: :frowning:

I was not sure how to represent the group of numbers in the NumberGroup interface, so I just had a field int[] array.

@rdeing2614 @harsh98 you actually put the public keyword in:

public interface NumberGroup
{
public boolean contains (int num);
}

Do you guys think college board will take points if I actually implemented the method in the interface.

Were we supposed to put the method contain for the Range class in 4b? It was kinda vague imo because we weren’t known if the class is abstract or not. If it were not abstract, then it should have had a contains method (which I did), but it kinda seems redundant to put its body in 4b when the 4c asks you to write body for the same method in different class?

Just finished taking the test myself. It’s an interesting set of problems, to be sure.

Repeating Standard Disclaimer: my opinions here are based on my experiences as a reader, but my opinions are solely my own.

@harsh98 Your 1a solution looks good to me.

@unavailable Two small errors:
(1) ‘word’ should be declared as a private variable
(2) indexOf() takes a String as a parameter, and you passed it a char

@harsh98 depends on how many points are possible for that problem. If it’s like 1 or 2 point total, then you’ll probably get no credit, but if it’s larger (which I doubt because there are 2 other parts for 9 points total in 1 problem), you’ll probably get about half credit. I think they put heavy criterion on whether the method contains body or not.

@jkhuggins Thanks for going over it for me. Are you sure they will take points off for not making the word variable private? They never mentioned the scope in the question.

As for indexOf, i just tried it out in eclipse and seemed to work without errors.

@unavailable yeah i think it’s been in past rubrics that instance variables should be declared private. http://apcentral.collegeboard.com/apc/public/repository/ap08_comp_sci_a_q4.pdf

Yeah for #2, I made an if statement, and 5-7 else if statements after. Would that work?

@AlphaDragon you’re not supposed to declare any variables in the interface definition; there are ways to implement NumberGroups without explicitly listing everything in the group.

@AverageStudent97 yes, you have to give a definition for contains() in NumberGroup. The description for that part of the problem says that the Range class is a NumberGroup, so you have to declare that Range implements NumberGroup and provide the appropriate definition. The fact that MultipleGroups is also a NumberGroup isn’t relevant to part (b).

@AverageStudent97 That sucks then, there goes an easy point.

@unavailable I stand corrected. There is a version of the indexOf() method in the String class which takes a char (technically, an int) as its argument. It’s outside of the AP Java subset, but it’s legal, so … that won’t be a deduction.

@sb98park you mean you made an if statement for every character? I don’t think that would work as they did not specify a limit to the sizes of the words / guesses