Implementing ArrayList Algorithms FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

Ribbon has getters getLength and getColor. Write longest so it returns the largest getLength() in ribbons. Assume ribbons is not empty.

public class Ribbon {
    private int length;
    private String color;
    public Ribbon(int length, String color) {
        this.length = length;
        this.color = color;
    }
    public int getLength() {
        return length;
    }
    public String getColor() {
        return color;
    }
}

public int longest(ArrayList<Ribbon> ribbons) {
    /* write this method */
}

Question 2 of 5

Write hasRepeatLabel so it returns true if any two Peg objects in pegs have the same getColor(), not only neighbors. Return false if all colors are unique. Peg has getColor().

public class Peg {
    private int height;
    private String color;
    public Peg(int height, String color) {
        this.height = height;
        this.color = color;
    }
    public int getHeight() {
        return height;
    }
    public String getColor() {
        return color;
    }
}

public boolean hasRepeatLabel(ArrayList<Peg> pegs) {
    /* write this method */
}

Question 3 of 5

Write dropRow so every Ticket with getRow() equal to target is removed. Adjust the index after each remove.

public class Ticket {
    private int row;
    public Ticket(int row) {
        this.row = row;
    }
    public int getRow() {
        return row;
    }
}

public void dropRow(ArrayList<Ticket> pile, int target) {
    /* write this method */
}

Question 4 of 5

Write rotateLeft so the first element of ids moves to the end and every other element shifts one index toward 0. Use get and set. Assume ids is not empty.

public void rotateLeft(ArrayList<Integer> ids) {
    /* write this method */
}

Question 5 of 5

Stamp has getInk and getTown. Write allDark so it returns true only when every stamp in the list has getInk() at least 5. Return true for an empty list. Then state the result for a list of three stamps with ink 5, 9, and 4.

public class Stamp {
    private int ink;
    private String town;
    public Stamp(int ink, String town) {
        this.ink = ink;
        this.town = town;
    }
    public int getInk() {
        return ink;
    }
    public String getTown() {
        return town;
    }
}

public boolean allDark(ArrayList<Stamp> box) {
    /* write this method */
}