FRQ 1: Digits Class — Homework Assignment

7 min read

Overview

This question involves identifying and processing the digits of a non-negative integer. The Digits class has an instance variable digitList which stores the individual digits of a number.

Learning Objectives

  • Implement a Java class constructor that populates an ArrayList
  • Traverse a list and compare adjacent elements
  • Handle edge cases (single digit and zero)

Instructions

  • Complete Part A first, then Part B
  • Run each code cell and verify expected output
  • Complete the final combined challenge
  • Add screenshots of each code runner result in the placeholder sections

Submission

  • Include screenshots of Part A, Part B, and Combined code runners
  • Add a few sentences about takeaways and AP FRQ prep
  • Submit before the due time listed by your class

Part A — Constructor

Implements digit extraction in left-to-right order, including num == 0.

import java.util.ArrayList;

public class Main {
    static class Digits {
        private ArrayList<Integer> digitList;

        /** Constructs a Digits object that represents num. */
        public Digits(int num) {
            digitList = new ArrayList<Integer>();

            if (num == 0) {
                digitList.add(0);
                return;
            }

            while (num > 0) {
                digitList.add(0, num % 10);
                num /= 10;
            }
        }

        public ArrayList<Integer> getDigitList() {
            return digitList;
        }
    }

    public static void main(String[] args) {
        Digits d1 = new Digits(0);
        Digits d2 = new Digits(7);
        Digits d3 = new Digits(1356);
        Digits d4 = new Digits(65310);

        System.out.println("Part A Tests:");
        System.out.println("0 -> " + d1.getDigitList());
        System.out.println("7 -> " + d2.getDigitList());
        System.out.println("1356 -> " + d3.getDigitList());
        System.out.println("65310 -> " + d4.getDigitList());
    }
}
run:Main.main(null);

Screenshot Placeholder — Part A

  • Insert code runner screenshot here

Part A Screenshot Placeholder

Part B — isStrictlyIncreasing

Uses a loop over adjacent digits and returns false on first violation.

import java.util.ArrayList;

public class Main {
    static class Digits {
        private ArrayList<Integer> digitList;

        // Constructor provided
        public Digits(int num) {
            digitList = new ArrayList<Integer>();
            if (num == 0) {
                digitList.add(0);
                return;
            }
            while (num > 0) {
                digitList.add(0, num % 10);
                num /= 10;
            }
        }

        /** Returns true if digits are strictly increasing. */
        public boolean isStrictlyIncreasing() {
            for (int i = 1; i < digitList.size(); i++) {
                if (digitList.get(i) <= digitList.get(i - 1)) {
                    return false;
                }
            }
            return true;
        }
    }

    public static void main(String[] args) {
        Digits a = new Digits(7);
        Digits b = new Digits(1356);
        Digits c = new Digits(1336);
        Digits d = new Digits(1536);
        Digits e = new Digits(65310);

        System.out.println("Part B Tests:");
        System.out.println("7 -> " + a.isStrictlyIncreasing());
        System.out.println("1356 -> " + b.isStrictlyIncreasing());
        System.out.println("1336 -> " + c.isStrictlyIncreasing());
        System.out.println("1536 -> " + d.isStrictlyIncreasing());
        System.out.println("65310 -> " + e.isStrictlyIncreasing());
    }
}
run:Main.main(null);

Screenshot Placeholder — Part B

  • Insert code runner screenshot here

Part B Screenshot Placeholder

Task — Combine

Implement both parts together from scratch.

import java.util.ArrayList;

public class Main {
    static class Digits {
        private ArrayList<Integer> digitList;

        /** Constructs a Digits object that represents num. */
        public Digits(int num) {
            digitList = new ArrayList<Integer>();

            if (num == 0) {
                digitList.add(0);
                return;
            }

            while (num > 0) {
                digitList.add(0, num % 10);
                num /= 10;
            }
        }

        /** Returns true if digits are strictly increasing. */
        public boolean isStrictlyIncreasing() {
            for (int i = 1; i < digitList.size(); i++) {
                if (digitList.get(i) <= digitList.get(i - 1)) {
                    return false;
                }
            }
            return true;
        }

        public ArrayList<Integer> getDigitList() {
            return digitList;
        }
    }

    public static void main(String[] args) {
        Digits[] tests = {
            new Digits(7),
            new Digits(1356),
            new Digits(1336),
            new Digits(1536)
        };

        int[] nums = {7, 1356, 1336, 1536};

        System.out.println("Combined Tests:");
        for (int i = 0; i < tests.length; i++) {
            System.out.println(nums[i] + " -> digits: " + tests[i].getDigitList() +
                ", strictlyIncreasing: " + tests[i].isStrictlyIncreasing());
        }
    }
}
run:Main.main(null);

Screenshot Placeholder — Combined

  • Insert code runner screenshot here

Combined Screenshot Placeholder

Grading Rubric — Total: 9 points

Part (a) - Digits constructor - 5 points

  • +1 Constructs digitList (initializes the ArrayList)
  • +1 Identifies a digit in num
  • +1 Adds at least one identified digit to the list
  • +1 Adds all identified digits to the list (inside a loop)
  • +1 On exit: digitList contains all and only the digits of num in correct order

Part (b) - isStrictlyIncreasing - 4 points

  • +1 Compares at least one consecutive pair
  • +1 Correctly detects out-of-order pair (inside a traversal loop)
  • +1 Compares all necessary consecutive pairs
  • +1 Returns true iff all consecutive pairs are in order

Automatic Deductions

  • -2 Uses a confused identifier instead of digitList

Main Takeaways (Submission Notes)

I implemented the Digits constructor by repeatedly extracting digits with % 10 and inserting at index 0 so the final list stays in left-to-right order. I also handled the edge case num == 0 so the list is [0] instead of empty.

For isStrictlyIncreasing, I loop through adjacent pairs and immediately return false when a digit is less than or equal to the previous one. This makes the method efficient and matches the strict inequality requirement exactly.

This helps me on AP FRQs because I can now structure solutions around clear loop invariants, edge-case handling, and rubric-aligned logic that earns each point intentionally.