Unit 10 ยท Integration and capstone readiness
A recursive method solves a problem by solving a smaller version of the same problem. Every valid input must move toward a base case. For factorial, the base case is 0! = 1.
static long factorial(int n) {
if (n < 0) throw new IllegalArgumentException("n must be non-negative");
if (n == 0) return 1;
return n * factorial(n - 1);
}Trace factorial(3) as calls down to factorial(0), then returns back upward. Tests should include normal, boundary, and invalid cases.
n.Mastery task: Plan a capstone study tracker with a class model, file format, validation rules, five acceptance tests, and one deliberately failing test that you then fix.