2019 FRQ
2019 FRQ
public class WordMatch {
private String secret;
public WordMatch (String word) {
this.secret = word;
}
public int scoreGuess (String guess) {
String word_copy = secret;
int score = 0;
for (int i = 0; i<secret.length(); i++) {
if (word_copy.indexOf(guess) == 0) score++;
word_copy = word_copy.substring(1, word_copy.length());
}
return score*guess.length()*guess.length();
}
public static void main (String[] args) {
WordMatch game1 = new WordMatch("mespoptamia");
System.out.println(game1.scoreGuess("m"));
System.out.println(game1.scoreGuess("eso"));
System.out.println(game1.scoreGuess("pot"));
System.out.println(game1.scoreGuess("amia"));
System.out.println();
WordMatch game2 = new WordMatch("spiderman");
System.out.println(game2.scoreGuess("s"));
System.out.println(game2.scoreGuess("pi"));
System.out.println(game2.scoreGuess("der"));
System.out.println(game2.scoreGuess("man"));
}
}
WordMatch.main(null);
public class WordMatch {
private String secret;
public WordMatch (String word) {
this.secret = word;
}
public int scoreGuess (String guess) {
String word_copy = secret;
int score = 0;
for (int i = 0; i<secret.length(); i++) {
if (word_copy.indexOf(guess) == 0) score++;
word_copy = word_copy.substring(1, word_copy.length());
}
return score*guess.length()*guess.length();
}
public String findBetterGuess (String guess1, String guess2) {
int score1 = scoreGuess(guess1);
int score2 = scoreGuess(guess2);
if (score1 > score2) return guess1;
if (score1 < score2) return guess2;
return (guess1.compareTo(guess2) > 0 ? guess1 : guess2);
}
public static void main (String[] args) {
WordMatch game1 = new WordMatch("concatenation");
System.out.println(game1.findBetterGuess("Elon", "Jeff"));
System.out.println(game1.findBetterGuess("King Tut", "Cleopatra"));
}
}
WordMatch.main(null);