FRQ - Methods Homework

public int getScore() { 
    //  initialize score as 0
    int score = 0; 
    // check if each level has been reached. 
    // if statements are nested to ensure that points in a level can only be attained if all previous levels' goals have been reached
    if (levelOne.goalReached()) { 
        score = levelOne.getPoints(); 
        if (levelTwo.goalReached()) { 
            score += levelTwo.getPoints(); 
            if (levelThree.goalReached()) { 
                score += levelThree.getPoints();
            }
        }
    } 
    // if bonus, multiply by 3
    if (isBonus()) { 
        score *= 3;
    } 
    return score;
}

b)

public int playManyTimes(int num) { 
    int highestScore = 0; 
    // iterate as many times as requested
    for (int i = 0; i < num; i++) { 
        // simulate and check if simulation is greater than the already existing maximum
        play();
        int score = getScore();
        if (score > highestScore) { 
            highestScore = score;
        }
    } 
    // return result
    return highestScore;
}

Comments

You are seeing this because your Disqus shortname is not properly set. To configure Disqus, you should edit your _config.yml to include either a disqus.shortname variable.

If you do not wish to use Disqus, override the comments.html partial for this theme.