Things to look out for

  1. Don’t have random code that isn’t necessary a. For example, random print statements shouldn’t be there
  2. Forgetting to declare variables
  3. Void methods and constructors shouldn’t return values

Steps to solving the problem

  1. Writing the class header (public class ClassName { ... })
  2. Declare the instance variables (private int skibidi;) a. Usually should be private
  3. Declare constructor header (public ClassName(...) { ... }) a. Should usually be public
  4. Declare method headers (public void sampleMethod(...) { ... }) a. Should usually be public, but it may be private if the question says so
  5. Write the actual logic in the methods now

Example - 2020 FRQ Part 2

9/9 Points

import java.util.Random;

public class GameSpinner {
    private int numSectors;
    private int lastSpin;
    private int runLength;
    private Random rand;

    public GameSpinner(int sectors) {
        numSectors = sectors;
        lastSpin = -1;
        runLength = 0;
        rand = new Random();
    }

    public int spin() {
        int result = rand.nextInt(numSectors) + 1;

        if (result == lastSpin) {
            runLength++;
        } else {
            runLength = 1;
            lastSpin = result;
        }

        return result;
    }

    public int currentRun() {
        return runLength;
    }
}