// CODE_RUNNER: DigitsPartB

import java.util.ArrayList;

public class Main {
    private ArrayList<Integer> digitList;

    // Constructor
    public Digits(int num) {
        digitList = new ArrayList<Integer>();

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

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

    public boolean isStrictlyIncreasing() {
        // YOUR CODE HERE
        return true;
    }

    public static void main(String[] args) {

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

        for (int n : tests) {
            Digits d = new Digits(n);
            System.out.println("Result for " + n + ": " + d.isStrictlyIncreasing());
        }
    }
}

Main.main(new String[0]);

// CODE_RUNNER: DigitsPartB

import java.util.ArrayList;

public class Digits {
    private ArrayList<Integer> digitList;

    // Constructor
    public Digits(int num) {
        digitList = new ArrayList<>();

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

        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) {

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

        for (int n : testNums) {
            Digits d = new Digits(n);
            System.out.println("Digits(" + n + ") -> " + d.isStrictlyIncreasing());
        }
    }
}

Digits.main(null);

// CODE_RUNNER: DigitsCompleteFillIn

import java.util.ArrayList;

public class Main {

    private ArrayList<Integer> digitList;

    /** Constructs an object that represents num.
     * Precondition: num >= 0
     */
    public Main(int num) {
        // YOUR CODE HERE - Part A
    }

    /** Returns true if the digits are strictly increasing */
    public boolean isStrictlyIncreasing() {
        // YOUR CODE HERE - Part B
        
        return true; // Placeholder
    }
    
    // Helper method
    public ArrayList<Integer> getDigitList() {
        return digitList;
    }

    public static void main(String[] args) {

        int[] tests = {15704, 1356};

        for (int value : tests) {
            Main obj = new Main(value);

            System.out.println("Number tested: " + value);
            System.out.println("Digit list -> " + obj.getDigitList());
            System.out.println("Increasing order? " + obj.isStrictlyIncreasing());
            System.out.println("-------------------");
        }
    }
}

Main.main(null);

Reflection on the Development Process

Skills and Concepts I Gained

  • I learned how to use a constructor to initialize an object and prepare its internal data structure when a new object is created.
  • I practiced using an ArrayList to store multiple values, specifically storing each digit of a number so they could be accessed individually.
  • I improved my understanding of loops and indexing, which allowed me to move through the list of digits and compare adjacent elements.
  • I learned how to combine loops with conditional statements to check whether digits were in strictly increasing order and return a boolean result.

Challenges I Faced During the Assignment

  • I initially struggled with extracting digits in the correct order, since using % 10 retrieves digits from right to left.
  • I had to figure out how to insert digits at the beginning of the ArrayList so the stored order matched the original number.
  • I made some mistakes with index comparisons in the loop, especially when comparing the current digit with the previous digit.
  • I also had to debug logical errors in the condition for strictly increasing digits, making sure the method returned false whenever a digit was less than or equal to the previous one.