HiddenWord
is #2 from the from the 2015 AP Computer Science A Free Response problems.
https://secure-media.collegeboard.org/digitalServices/pdf/ap/ap15_frq_computer_science_a.pdf
public class HiddenWord
{
private String word;
public HiddenWord(String word)
{
this.word = word;
}
public String getHint(String guess)
{
String hint = "";
for(int i = 0; i < word.length(); i++)
{
String guessLetter = guess.substring(i, i + 1);
if(word.substring(i, i + 1).equals(guessLetter))
hint += guessLetter;
else if(word.indexOf(guessLetter) != -1)
hint += "+";
else
hint += "*";
}
return hint;
}
}
See Class writing order for a technique to respond to AP CS FR that request an entire class.
See Strings on the AP CS A Exam for an explanation of String
methods and String
concatenation.
2015 AP CS Exam Free Response Solutions
- DiverseArray Free Response Solution
- SparseArray Free Response Solution
- NumberGroup Free Response Solution
Help & comments
Get help from AP CS Tutor Brandon Horn