2021 FRQ 1: ---------------+ WordMatch.java | ---------------+ /** * 2021 frq 1 * * implementation and test code: Bradley B '24 * @version February 29, 2024 */ public class WordMatch { /** The secret string */ private String secret; /** Constructs a WordMatch object with the given secret string of lowercase letters */ public WordMatch(String word) { this.secret = word.toLowerCase(); } /** Returns a score for guess, as described in part (a). * Precondition: 0 < guess.length() <= secret.length() */ public int scoreGuess(String guess) { //replace the following with your solution to part (a) here: return -1; } /** Returns the better of the two guesses, as determined by scoreGuess and the rules for a * tie=breaker that are described in part (b). * Precondition: guess1 and guess 2 contain all lowercase letters. * guess1 is not the same as guess2. */ public String findBetterGuess(String guess1, String guess2) { //replace the follwing with your solution to part (b) here: return ""; } public String getSecret() { return secret; } public String isCorrect(int score, int correct) { if(score == correct) return "Pass!"; return "Fail!"; } public String isCorrect(String score, String correct) { if(score.equals(correct)) return "Pass!"; return "Fail!"; } public static void main(String[] args) { WordMatch test = new WordMatch("mississippi"); /** * part (a) scoreGuess method test */ System.out.println("\n" + "\n" + "\n" + "The secret word is " + test.getSecret()); System.out.println("\n" + "Part (a): Testing scoreGuess()" + "\n"); System.out.println("\n" + "Guess: [i] should return 4 and your code returns: " + test.scoreGuess("i") + "\t" + test.isCorrect(4,test.scoreGuess("i"))); System.out.println("\n" + "Guess: [iss] should return 18 and your code returns: " + test.scoreGuess("iss") + "\t" + test.isCorrect(18,test.scoreGuess("iss"))); System.out.println("\n" + "Guess: [issipp] should return 36 and your code returns: " + test.scoreGuess("issipp") + "\t" + test.isCorrect(36,test.scoreGuess("issipp"))); System.out.println("\n" + "Guess: [mississippi] should return 121 and your code returns: " + test.scoreGuess("mississippi") + "\t" + test.isCorrect(121,test.scoreGuess("mississippi"))); /** * part (b) findBetterGuess method test */ System.out.println("\n" + "\n" + "Part (b): Testing findBetterGuess()" + "\n"); System.out.println("\n" + "Guess: [ss , pp] should return ss and your code returns: " + test.findBetterGuess("ss", "pp") + "\t" + test.isCorrect("ss", test.findBetterGuess("ss", "pp"))); System.out.println("\n" + "Guess: [mis , sip] should return sip and your code returns: " + test.findBetterGuess("mis", "sip") + "\t" + test.isCorrect("sip", test.findBetterGuess("mis", "sip"))); System.out.println("\n" + "Guess: [missi , iss] should return missi and your code returns: " + test.findBetterGuess("missi", "iss") + "\t" + test.isCorrect("missi", test.findBetterGuess("missi", "iss"))); } } -------------------+ WordMatchGame.java | -------------------+ /** * 2021 frq 1 * * implementation and test code: Bradley B '24 * @version February 29, 2024 */ import java.util.*; public class WordMatchGame{ public static void main(String[] args){ Scanner k = new Scanner(System.in); System.out.print("Enter Secret Word: "); String secret = k.nextLine(); for (int i = 0; i < 60; i++){ System.out.print("\n"); } String g = ""; WordMatch game = new WordMatch(secret); int maxPoints = game.scoreGuess(secret); int points = 0; System.out.println("Take a guess: "); while (points != maxPoints){ g = k.nextLine(); points = game.scoreGuess(g); System.out.println("Points: " + points); if (points != maxPoints) System.out.println("Take another guess: "); } System.out.print("Congrats you win!!!!!"); } }