2023 AP Computer Science A FRQ

Поделиться
HTML-код
  • Опубликовано: 15 июл 2024
  • Write the moveCandyToFirstRow method, which attempts to ensure that the box element at row 0 and column col contains a piece of candy, using the following steps.
    • If the element at row 0 and column col already contains a piece of candy, then box is unchanged and the method returns true.
    • If the element at row 0 and column col does not contain a piece of candy, then the method searches the remaining rows of column col for a piece of candy. If a piece of candy can be found in column col, it is moved to row 0, its previous location is set to null, and the method returns true; otherwise, the method returns false.
    In the following example, the grid represents the contents of box. An empty square in the grid is null in box. A non-empty square in the grid represents a box element that contains a Candy object. The string in the square of the grid indicates the flavor of the piece of candy.
    The method call moveCandyToFirstRow(0) returns false because the box element at row 0 and column 0 does not contain a piece of candy and there are no pieces of candy in column 0 that can be moved to row 0. The contents of box are unchanged. The method call moveCandyToFirstRow(1) returns true because the box element at row 0 and column 1 already contains a piece of candy. The contents of box are unchanged.
    The method call moveCandyToFirstRow(2) moves one of the two pieces of candy in column 2 to row 0 of column 2, sets the previous location of the piece of candy that was moved to null, and returns true. The new contents of box could be either of the following.
    Intro: 00:00
    Writing the pseudocode: 00:46
    Writing the code: 03:15
    Testing the first method call: 06:29
    Testing the second method call: 08:02
    Testing the third method call: 08:39
    Solution: 10:49

Комментарии •