By LearnAllStudents Editorial Team. Source check dates are listed below.
Follow the worked example
A shipping function should report true for free shipping when the order is at least 50 dollars. Use integer cents to model the boundary exactly.
Test 4999 → false, 5000 → true and 5001 → true. A mistaken strict greater-than comparison would fail only the middle case.
If the spec also disallows negative totals, decide whether the caller validates them or the method must return a particular result. Those are different contracts.
Place the listing inside a Java class. Try the worked example’s inputs from its main method.
static boolean earnsFreeShipping(int subtotalInCents) {
return subtotalInCents >= 5000;
}
static boolean eligibleAge(int age) {
return age >= 13 && age <= 17;
}Design tests to separate plausible mistakes
For an inclusive lower bound, one input just below the boundary and one exactly on it separate the intended rule from an accidental strict check. Pair those with a normal input so you can detect a failure elsewhere in the method.
Try it yourself
A pass is valid for ages 13 through 17 inclusive. Select four boundary tests.
Check your reasoning
12 → false, 13 → true, 17 → true, 18 → false.
Use the idea in a different situation
Which cases detect replacing || with && in an out-of-range check age < 13 || age > 17?
Check the second task
Use 12 and 18. Either should be rejected, but neither satisfies both conditions together.
For parents
Ask, “What is the smallest test that would catch changing “at least 50” to “more than 50”?”
They should choose exactly 50 and state the opposite expected results under the two rules.
Write the expected result for 49, 50 and 51 before running any code. Ask which result distinguishes the two rules.
How a tutor would approach this
Write down the expected output or state before running the Java code. Compare it with the actual output, trace where they first differ and test the fix against another input that arrives at the same kind of boundary.
Frequently asked questions
What mistake should I look for first?
Choosing only numbers far from the threshold leaves < versus <= and > versus >= errors undetected.
How can I use this with a longer practice set?
Read the current course framework and official sample questions before deciding how to practise this technique in an exam-length task.
Are these official past-paper questions?
The worked example and practice tasks here are original. The sources section links to the official material for your course.
How can I tell if I can use the method on a new question?
Try the second task with the worked example covered. Explain which step needs to change and why before checking the answer.
Official sources
- College Board AP Computer Science A course and exam description (checked 2026-11-26)
Related pages
Try a free 30-minute demo
Work through a question with a tutor. No payment needed.
Request a free 30-minute demo