Chapter 16 — Combination Drills
These are not weekly reps. They are review drills — short Java programs that combine concepts from Chapters 9–15.
Do them in order. Each builds toward the final.
Ground rules:
- Type every line. No copy-paste.
- AI off.
- Compile and run after each.
- If a drill takes you over 90 minutes, stop, re-read the relevant chapter, then come back.
Drill 1 — Class + Constructor + Encapsulation
Build a Pilgrim class with private name, faith (int, 0–100), and courage (int, 0–100). Constructor takes name and starting values (clamped to range). Methods:
takeTrial(int severity)— subtracts from faith.takeEncouragement(int amount)— adds to faith, clamped at 100.boolean hasGivenUp()— returnsfaith <= 0.void print()— prints status.
Demo in a main: build a pilgrim, hit them with 3 trials and 2 encouragements, print.
Time: 25 minutes.
Drill 2 — Abstract Class + Subclasses
Build an abstract Encounter class with name, abstract engage(Pilgrim p), concrete getName().
Two concrete subclasses:
Trial extends Encounter— engage subtracts faith.Companion extends Encounter— engage adds faith.
Build a Pilgrim. Construct a Trial and a Companion. Call engage on each. Print the pilgrim’s status between calls.
Time: 30 minutes.
Drill 3 — Polymorphic ArrayList
Take Drill 2. Add the encounters to an ArrayList<Encounter>. Loop and call engage on each. Confirm the right behavior for each type.
Add a third type, Temptation, that subtracts courage instead of faith. Add it to the array.
Time: 25 minutes.
Drill 4 — Interface
Add an interface Strengthening with void strengthen(Pilgrim p).
Have Companion implements Strengthening. Have Mentor extends Companion implements Strengthening (a Mentor is a Companion with an extra-strong strengthen).
In your loop, after engage, also call strengthen on any encounter that implements Strengthening (use instanceof).
Time: 30 minutes.
Drill 5 — Whole-System Drill (Closest to Final)
Allot 75 minutes. Time yourself.
Build a complete system:
- Abstract
Encounterclass. - Three concrete subclasses:
Trial,Companion,Temptation. Each overridesengage. - Interface
Strengthening(implementing classes canstrengthen(Pilgrim)). - Interface
Testing(implementing classes return aint trialCost()). Pilgrimclass with faith and courage.- A
runJourney(Pilgrim p, ArrayList<Encounter> route)method that loops over the route. For each encounter:engage, then if Strengthening alsostrengthen, then if Testing accumulate the trial count. Stop early ifpilgrim.hasGivenUp(). - A
mainthat builds a route of 5 mixed encounters, runs the journey, prints the result.
This is the closest analog to the final. If you can ship this in 75 minutes, you are ready.
If you can’t yet, do another variant — different encounter types, different stats, different interfaces. Variety is the rep.
Drill 6 — Sample Final Prompt
Open code/SampleFinal.java. Read the prompt at the top.
Close the file. Open a blank one. Solve in 60 minutes.
Then compare to the reference. Note where you differed.
After the Drills
If you got through Drill 5 in close to 75 minutes with a working program, you’re ready.
If you got through Drill 5 in two hours and the program had bugs you couldn’t find — do another drill before the exam. Variations of the same shape. Don’t go in cold.
The students who do 3+ full-stack drills the week before the final score noticeably higher than the students who only do one. Six hours of your week. Worth it.
See you in the exam room.