Grade: .95/1

MCQ: 1/1

FRQ: 0.9/1

2021 FRQ

This question involves the WordMatch class, which stores a secret string and provides methods that compare other strings to the secret string. You will write two methods in the WordMatch class.

1a

Write the WordMatch method scoreGuess. To determine the score to be returned, scoreGuess finds the number of times that guess occurs as a substring of secret and then multiplies that number by the square of the length of guess. Occurrences of guess may overlap within secret.

thoughts before writing code:

number of times guess occurs - counter? for loop, if guess = substring of secret, counter++ multiplies by the square of the length of guess - guess.length(), times the length two times return score

public int scoreGuess(String guess) {
    counter = 0;
    for (i = 0, i <= secret.length(), i++) {  //bound error would occur
        if (guess == substring.secret(i)) {   //didn't account for guess that has multiple characters
            counter ++;
        }
    }
    score = counter * guess.length() * guess.length(); 
    return score;
}
|       for (i = 0, i <= secret.length(), i++) {  //bound error would occur
not a statement

|       for (i = 0, i <= secret.length(), i++) {  //bound error would occur
';' expected

Example Solution

public int scoreGuess(String guess){
    int count = 0;
    for(int i = 0; i < secret.length()-guess.length(); i++){  //avoid bound error
        if(secret.substring(i, i+guess.length()).equals(guess)){ . //account for guess lenghh > 1
            count ++;
        }
    }
    return count * guess.length() * guess.length();
}

Grade Myself According to AP Scoring Guidelines (i know it's not going to be good)

2/5

places that i missed points on:

Compares guess to a substring of secret - Responses will not earn the point if they use == instead of equals

Loops through all necessary substrings of secret (no bounds errors) - Responses will not earn the point if they skip overlapping occurrences

Loops through all necessary substrings of secret (no bounds errors) - Responses will not earn the point if they skip overlapping occurrences

avoid index out of bound (condition for for loop -> i < secret.length() - guess.length() )

Comparing String vs Comparing Numbers

comparing numbers - use == comparing strings - use .equal()

1b

Write the WordMatch method findBetterGuess, which returns the better guess of its two String parameters, guess1 and guess2. If the scoreGuess method returns different values for guess1 and guess2, then the guess with the higher score is returned. If the scoreGuess method returns the same value for guess1 and guess2, then the alphabetically greater guess is returned.

Thoughts before writing code

1) if guess1 and guess 2 have different values from scoreGuess method, compared which one is higher and reture the one, so use if else statement to compare 2) if same value, compared the alphabet using if statement (.compareTo())

public String findBetterGuess(String guess1, String guess2){
    if (scoreGuess(guess1) != scoreGuess(guess1)){ .  //different values
        if (scoreGuess(guess1) > scoreGuess(guess1)){
            return guess1;
        }
        else
            return guess2;
    }
    else if (scoreGuess(guess1) = scoreGuess(guess1)){ //same value
        if(guess1.compareTo(guess2) > 0) { 
            return guess1;
        }
        else
            return guess2;
    }
}

Solution

public String findBetterGuess(String guess1, String guess2){
    if (score.Guess(guess1) > score.Guess(guess1)){
        return guess1;
    }
    if (score.Guess(guess1) < score.Guess(guess1)){
        return guess2;
    }
    if(guess1.compareTo(guess2) > 0) { 
        return guess1;
    }
        return guess2;
}

Grade Myself According to AP Scoring Guidelines (did better on this one)

4/4

.compareTo()

.compareTo() compares two strings lexicographically returns 0 if the string is equal to the other string. A value less than 0 is returned if the string is less than the other string (less characters) and a value greater than 0 if the string is greater than the other string (more characters)

Reflection

Tbh this is the only frq that I did without looking things up on the internet, I wrote the code purely based on my existing knowledge. For me, the hardest part of these frqs was understanding the prompts and really knowing what I needed to write, I often became impatient because I didn't understand what I needed to write and I didn't know what those tables or other provided methods did. Because before I just wanted to get the assignment done, but now I know I'm not doing it for the grader or the teacher, I need to do more exercises like this to work on my knowledge and blog about what I did wrong and what I learned from it so that I can improve later on.

part b is relatively easier than part a for me because it is about comparing and making if else statement while part a requires more thinking and not only need if else statement.

unit2

Completed with Divya, but we don't have permission to the google form anymore, but here is an evidence