The First FRQ

The first FRQ primarily focuses around methods and control structures, which isn't too bad as far as I'm concerned. Methods are about the specific functions an object can perform, whereas control structures are mainly about the if, elseif, and else statemements that can branch a program out into different pathways. These are quite fundamental concepts for the Java language, so I think I know them pretty well already.

However, it's never a good idea to underestimate the difficulty of these questions, as these can easily make or break a 5 on the exam. That's why I'll be practicing them today in this blog.

2021

This FRQ is really annoying to put in, so I'll just link it here

The code block below has my work for both part a and b, with an additional main() function to test solutions (which is not there on the exam unfortunately).

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)
    {
    /* implementation not shown */
        this.secret = word;
        
    }
    /** Returns a score for guess, as described in part (a).
    * Precondition: 0 < guess.length() <= secret.length()
    */

    // START OF SOLUTION A
    public int scoreGuess(String guess) {

        // Tracks number of times the substring appears
        int occurrences = 0;

        // secret.length() - guess.length() to avoid index overflow with substring later on
        for (int i = 0; i <= secret.length() - guess.length(); i++) {

            // Checks if the substring is equal to the guess
            if (secret.substring(i, i + guess.length()).contains(guess)) {
                occurrences++;

                // Moves forward by guess.length() - 1 to move forward in the string (and avoid repeats)
                // -1 is included because i++ 
                i += guess.length() - 1;
            }
        }
        return occurrences * guess.length() * guess.length();
    }
    // END OF SOLUTION A

    // START OF SOLUTION B
    public String findBetterGuess(String guess1, String guess2)
    { /* to be implemented in part (b) */ 
        if (scoreGuess(guess1) > scoreGuess(guess2)) {
            return guess1;
        } else if (scoreGuess(guess2) > scoreGuess(guess1)) {
            return guess2;
        } else if (guess1.compareTo(guess2) > 0) {
                return guess1;
        } else {
                return guess2;
            }
        }
    // END OF SOLUTION B

    public static void main(String[] args) {

        WordMatch testA = new WordMatch("mississippi");
        System.out.println(testA.scoreGuess("issippi"));
        System.out.println(testA.scoreGuess("mississippi"));

        WordMatch testB = new WordMatch("concatenation");
        System.out.println(testB.findBetterGuess("ten" , "nation"));
        System.out.println(testB.findBetterGuess("con", "cat"));
    }

}

WordMatch.main(null);
49
121
nation
con

The Process

For the first time solving an FRQ, I don't think it was too bad (although we had a pretty big handicap with being able to test solutions).

The first part wasn't too hard; the iteration was a bit different but we eventually came upon a solution to our problems. Troubleshooting it was probably the hardest part though. Finding the subtle mistakes that we made in the process was painful, even with the ability to compile.

The second part was pretty easy aside from one part. It was easy enough to compare the two values using the previous scoreGuess() function, but we didn't know how to compare alphabetically. We were completely stuck and I was even considering using a for loop to iterate through each letter, but eventually I realized that the compareTo() method existed for Strings, and that basically solved the problem.

After completing it, Rohan and I eventually made a more simplified version on Rohan's version of the blog, especially improving part A. We found part A to be the hardest part of the entire ordeal, so we got to work to find a better solution. Eventually we simplified it down a few lines, so I think we definitely improved on making those kinds of solutions.

Overall, I think we did a decent job. Obviously it isn't good enough for the AP Exam, but I think we can definitely get the hang of creating solutions like these pretty quickly in the future.