Skip to main content Link Menu Expand (external link) Document Search Copy Copied

FRQ No.1 โ€ข 20 min read

Description

the hacks for all of the frq 1

FRQ 1, Method and Control Structures:

Question #6, 2022

Write the getScore method, which returns the score for the most recently played game. Each game consists of three levels. The score for the game is computed using the following helper methods.

  • The isBonus method of the Game class returns true if this is a bonus game and returns false otherwise.
  • The goalReached method of the Level class returns true if the goal has been reached on a particular level and returns false otherwise.
  • The getPoints method of the Level class returns the number of points recorded on a particular level. Whether or not recorded points are earned (included in the game score) depends on the rules of the game, which follow. The score for the game is computed according to the following rules.
  • Level one points are earned only if the level one goal is reached. Level two points are earned only if both the level one and level two goals are reached. Level three points are earned only if the goals of all three levels are reached.
  • The score for the game is the sum of the points earned for levels one, two, and three.
  • If the game is a bonus game, the score for the game is tripled.

FRQ Response:

boring code โ€ฆ..๐Ÿคข๐Ÿคฎ๐Ÿ˜•๐Ÿ˜’

import java.util.Random;

class Level {
    private int levelNum;
    private boolean goalReached;
    private int points;

    public Level(int levelNum, boolean goalReached, int points) {
        this.levelNum = levelNum;
        this.goalReached = goalReached;
        this.points = points;
    }

    public boolean isGoalReached() {
        return goalReached;
    }

    public int getPoints() {
        return points;
    }
}

class Game {
    private boolean isBonus;
    private Level[] levels;

    public Game() {
        this.isBonus = generateRandomBonus(); // Set isBonus randomly
        levels = new Level[3]; // there are 3 levels
    }

    public void addLevel(Level level, int levelNum) {
        levels[levelNum - 1] = level;
    }

    public int calculateScore() {
        int score = 0;

        if (levels[0] != null && levels[0].isGoalReached()) {
            score += levels[0].getPoints();
        }

        if (levels[1] != null && levels[1].isGoalReached() && levels[0] != null && levels[0].isGoalReached()) {
            score += levels[1].getPoints();
        }

        if (levels[2] != null && levels[2].isGoalReached() && levels[1] != null && levels[1].isGoalReached()
                && levels[0] != null && levels[0].isGoalReached()) {
            score += levels[2].getPoints();
        }

        if (isBonus) {
            score *= 2;
        }

        return score;
    }

    // Generate a random boolean for isBonus
    private boolean generateRandomBonus() {
        Random random = new Random();
        return random.nextBoolean();
    }

    // Getter method for isBonus
    public boolean isBonus() {
        return isBonus;
    }
}

public class Main {
    public static void main(String[] args) {
        Level level1 = new Level(1, true, 3);
        Level level2 = new Level(2, false, 4);
        Level level3 = new Level(3, false, 2);

        Game game = new Game(); // isBonus will be set randomly
        game.addLevel(level1, 1);
        game.addLevel(level2, 2);
        game.addLevel(level3, 3);

        int score = game.calculateScore();
        System.out.println("Is Bonus Game: " + game.isBonus());
        System.out.println("Score: " + score);
    }
}
Main.main(null);

Is Bonus Game: true
Score: 6

fun code ๐Ÿฅณ๐ŸŽŠ๐ŸŽ‰๐Ÿ™Œ๐Ÿพ!!!!!!!

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

class Question {
    private String question;
    private String answer;

    public Question(String question, String answer) {
        this.question = question;
        this.answer = answer;
    }

    public String getQuestion() {
        return question;
    }

    public String getAnswer() {
        return answer;
    }
}

class Level {
    private int points;

    public Level() {
        this.points = 0;
    }

    public void recordPoints(int points) {
        this.points += points;
    }

    public int getPoints() {
        return points;
    }

    public boolean goalReached() {
        return points >= 3; // Adjust the goal as needed
    }
}

class Game {
    private static final int NUM_ROUNDS = 3;
    private static final int BONUS_CHANCE_PERCENT = 30; // num is percentage (e.g., 30%)

    private List<Question> questions;
    private Level level;
    private Random random;

    public Game() {
        questions = new ArrayList<>();
        level = new Level();
        random = new Random();

        // Add your questions here
        questions.add(new Question("What is the capital of France?", "Paris"));
        questions.add(new Question("What is the largest planet in our solar system?", "Jupiter"));
        questions.add(new Question("How many continents are there?", "7"));
        questions.add(new Question("Which animal is known as the 'King of the Jungle'?", "Lion"));
        questions.add(new Question("What is the smallest prime number?", "2"));
        questions.add(new Question("What is the largest mammal on Earth?", "Blue whale"));
        questions.add(new Question("Which planet is known as the 'Red Planet'?", "Mars"));
        questions.add(new Question("What is the chemical symbol for water?", "H2O"));
        questions.add(new Question("Which country is famous for its kangaroos?", "Australia"));
        questions.add(new Question("What is the capital of France?", "Paris"));
        questions.add(new Question("How many bones are there in the adult human body?", "206"));
        questions.add(new Question("What gas do plants absorb from the atmosphere?", "Carbon dioxide"));
        questions.add(new Question("What is the national flower of Japan?", "Cherry blossom"));
        questions.add(new Question("What is the largest ocean in the world?", "Pacific Ocean"));
        questions.add(new Question("Who wrote the play 'Romeo and Juliet'?", "William Shakespeare"));
        questions.add(new Question("What is the chemical symbol for gold?", "Au"));
        questions.add(new Question("How many sides does a hexagon have?", "6"));
        questions.add(new Question("Which gas do plants release during photosynthesis?", "Oxygen"));
        questions.add(new Question("What is the Earth's primary source of energy?", "The Sun"));
        questions.add(new Question("What is the largest desert in the world?", "Antarctica"));
        questions.add(new Question("Who painted the Mona Lisa?", "Leonardo da Vinci"));

    }
    public boolean isBonus() {
        return random.nextInt(100) < BONUS_CHANCE_PERCENT;
    }
    
     

    public void start() {
        Scanner scanner = new Scanner(System.in);

        System.out.println("Welcome to the Quiz Game!");

        boolean bonusRound = isBonus();
        System.out.println("Bonus Round: " + (bonusRound ? "On" : "Off"));

        for (int round = 1; round <= NUM_ROUNDS; round++) {
            System.out.println("Round " + round);
            Question currentQuestion = getRandomQuestion();
            System.out.println(currentQuestion.getQuestion());

            String userAnswer = scanner.nextLine();
            if (userAnswer.equalsIgnoreCase(currentQuestion.getAnswer())) {
                System.out.println("Correct! You earned 1 point.");
                level.recordPoints(1);
            } else {
                System.out.println("Incorrect! The correct answer was: " + currentQuestion.getAnswer());
            }
        }

        if (isBonus()) {
            System.out.println("Bonus Round!");
            Question bonusQuestion = getRandomQuestion();
            System.out.println(bonusQuestion.getQuestion());

            String userAnswer = scanner.nextLine();
            if (userAnswer.equalsIgnoreCase(bonusQuestion.getAnswer())) {
                System.out.println("Correct! You earned 3 points.");
                level.recordPoints(3);
            } else {
                System.out.println("Incorrect! The correct answer was: " + bonusQuestion.getAnswer());
            }
        }

        System.out.println("Game Over!");
        System.out.println("Your total points: " + level.getPoints());
        System.out.println("Goal reached: " + level.goalReached());
    }

    private Question getRandomQuestion() {
        int randomIndex = random.nextInt(questions.size());
        return questions.get(randomIndex);
    }
}

public class Main {
    public static void main(String[] args) {
        Game game = new Game();
        game.start();
    }
}

Main.main(null);
Welcome to the Quiz Game!
Bonus Round: Off
Round 1
What is the smallest prime number?


Correct! You earned 1 point.
Round 2
Which gas do plants release during photosynthesis?
Correct! You earned 1 point.
Round 3
What gas do plants absorb from the atmosphere?
Incorrect! The correct answer was: Carbon dioxide
Game Over!
Your total points: 2
Goal reached: false

Grading:

I took very similar steps to the the frq question answer. the key difference is that collegeboard wrote their code with their less verbose code and i wrote mine in java with is a more complex language. I also used the variable names that collegeboard wanted me to use. if was a collegeboard grader, what a boring job, I would give 4/4 because I followed similarly to what collegeboard wanted.

Reflection:

the first time that i represented the frq to the crossover team, my code didnโ€™t run and i had to resort to python, but now i can assure you that this java codes as well as a well fed horse. To be honest, chatgpt helped me to write at least half of this code, but i understand the logic and the process and how the code should be. the things i need to improve my knowledge on is java because if i donโ€™t learn it properly now, it will be difficult for me in future when i have to write bigger and code heavy projects. overall, i am happy that i was able to solve this frq in java and present it clearly to my crossover team.