Come Back Later

The Course
•
4 min read

Return after two or three days. Do not begin by rereading solutions. Retrieval practice asks you to produce an idea with less help, then use feedback to repair what you missed. This is extra review, outside the core Day 7 study estimate. There is no timer or penalty for looking up syntax after a first attempt.

Three short challenges

First, write a method that totals nonnegative durations at or above a supplied minimum. State its empty-input behavior and use at least one value exactly at the threshold. Second, draw two object variables pointing to the same Session, then draw two independently constructed sessions. Explain which state changes are shared in each drawing. Third, describe how to recover from one malformed duration and still accept the next valid input pair.

For each challenge, try from memory, run a small example, compare with the contract and explain the first difference. Record one thing you needed to look up and revisit that exact concept tomorrow. A checked completion box is a record of activity, not evidence that you can independently solve a new problem.

Rebuild a tiny multi-file project

Make Main.java and Session.java again without opening the old source. Keep fields private and use a constructor plus one useful instance method. In the browser, use the existing Main.java and Session.java tabs in Day 5’s Multiple Source Files lesson: select all the code in each tab and rebuild it from memory. The widget does not add new tabs. Alternatively, create the two files in a local project folder. Consult the original example only after your first attempt. If a helper cannot be found, check spelling, filename, entry and imports before changing its behavior.

Do not rush into frameworks to avoid these foundations. Methods, clear data, small tests and honest failure handling remain useful even when later libraries hide more infrastructure. Intermediate work can add richer collections, interfaces, file I/O and build tools after the basic contracts feel familiar.

A prediction to attempt before opening the answer Java
public class Main {
    public static void main(String[] args) {
        int[] original = {10, 25};
        int[] alias = original;
        alias[0] = 30;

        System.out.println(original[0]);
        System.out.println(original == alias);
    }
}
Check your prediction
30
true

The array reference was copied, not the array elements. This is the same reference idea as aliasing a Session. To build an independent array, allocate another array and copy the elements deliberately.

Your turn

Exercise

Rebuild a threshold count

Without the earlier solution, write countAtLeast(int[] values, int minimum) returning how many values reach the threshold. For {10,25,40} with 25, return 2. Check empty input and exactly-at-threshold input. Explain how this differs from totaling the selected durations.

Your workspace Java
public class Main {
    public static void main(String[] args) {
        System.out.println(countAtLeast(new int[] {10, 25, 40}, 25));
    }

    static int countAtLeast(int[] values, int minimum) {
        return 0; // Replace the placeholder.
    }
}
Hint 1: the idea

A count adds one for each match. It does not add the selected value.

Hint 2: a first step

Start the count before the loop. Include equality in the comparison, and return only after visiting the whole array.

Show one solution
public class Main {
    public static void main(String[] args) {
        System.out.println(countAtLeast(new int[] {10, 25, 40}, 25));
    }

    static int countAtLeast(int[] values, int minimum) {
        int count = 0;

        for (int value : values) {
            if (value >= minimum) {
                count++;
            }
        }

        return count;
    }
}
2

Change it and explain

Use a simple learning log: attempted unaided, what failed, what feedback showed, and the next variation to try. Repeat a fresh small task rather than opening the same finished code and recognizing it. If you can explain a rule but cannot write it yet, reduce the problem to one method and one boundary case.

You have learned a useful beginning, not all of Java. Keep using a real JDK for work beyond the browser’s documented subset, and keep the habit of separating a compiler’s guarantees from runtime evidence and the product rules you choose.

Was this article helpful?

Your response is saved on this device.