You build a fitness program in Java by modeling the domain first—exercises, workouts, weeks, and progression rules—then wiring those objects into computation and output. The key condition is deciding early whether the "program" is a static training plan (templates and schedules) or a generator that adapts to a trainee's inputs; Java handles both, but the design differs. This guide walks through a console-first implementation using plain Java and no external libraries, with checkpoints so you know each stage works before adding the next.
I'll treat "fitness program" as a strength-training plan: exercises grouped into sessions, sessions spread across a week, and loads progressing over time. The same structure fits cardio plans with minor changes.
Anatomy of a Fitness Program Before Any Code
A training program is really four layers stacked on top of each other. Exercises define movements and their attributes. Workout sessions bundle exercises with sets, reps, and rest. A weekly schedule places sessions on days and handles recovery. A progression model decides how the numbers change week to week.
Getting this mapping wrong is the most common reason beginner Java fitness apps become unmaintainable. If you put "3 sets of 10" as free text inside an exercise class, you can't compute weekly volume, and you can't regenerate a plan. If you make everything a String, nothing validates.
The modeling decision that matters most: separate the catalog (what exercises exist) from the prescription (what a specific trainee does with them). An exercise like a barbell squat is a reusable definition. "Squat, 4 sets of 5 at 80% effort, 3 minutes rest" is a prescription that belongs to one session in one program.
A second decision is units. Store weights in kilograms internally, with a single conversion point at input and output. Mixed pounds and kilograms inside the model will produce silent bugs that only appear when someone compares weekly volume.
Prerequisites and Project Setup
Before writing code, confirm three things. You need a JDK of version 17 or later (records help, though the code below sticks to classes so it reads on any modern JDK). You need a build path—a plain javac/java workflow is enough, though Maven or Gradle works fine. And you need a way to run and edit code: an IDE or a simple folder of .java files.
Choose a package name, for example fitness, and create these files in one directory:
1: Exercise.java — the catalog entry. 2: SetPlan.java — one prescribed set. 3: WorkoutSession.java — a named group of set plans. 4: TrainingWeek.java — seven day slots referencing sessions. 5: Trainee.java — inputs used for generation: goal, experience, available days, equipment. 6: ProgramGenerator.java — builds a plan from a trainee. 7: Main.java — console entry point.
Check success by compiling after each file: javac fitness/*.java should produce .class files with no errors. If you get "package does not exist," your folder structure doesn't match the package declaration—move the files under a fitness/ directory.
Step 1: Model Exercises as a Catalog
Start with a class that describes an exercise without prescribing it. Include an identifier, a name, the primary muscle group, the equipment needed, and a difficulty tier. An enum for muscle group and equipment keeps validation cheap.
A small catalog of, say, fifteen exercises gives you enough variety to test generation. Include at least two options per muscle group and a bodyweight fallback for each, so equipment filtering never returns an empty list.
Success check: construct the catalog in Main and print it. If a typo in an enum constant slips through, the compiler catches it—this is exactly why enums beat strings here.
One design note: resist adding fields for reps or weight to Exercise. That's prescription data, and it belongs in the next class.
Step 2: Represent Sets, Reps, and Rest
A SetPlan captures one prescribed set: target reps, optional target weight, rest after the set in seconds, and an effort indicator. Using a percentage of estimated one-rep max (1RM) is more portable than absolute weight because it survives a trainee's strength changes.
Volume for a set is reps multiplied by load. For percentage-based loads you can only compute volume once you know the trainee's 1RM, which is why 1RM lives in Trainee, not in the set. For bodyweight sets, count reps separately and don't add them to tonnage — that keeps a single definition of "volume" honest instead of mixing incompatible units.
Worked estimate: if a trainee's estimated squat 1RM is 100 kg, a set prescribed at 75% for 5 reps carries 75 kg × 5 = 375 kg of tonnage. Four such sets total 1,500 kg for that exercise. Reproduce this by hand against your printed output before trusting any weekly volume number.
Step 3: Build Workout Sessions
A session is a name plus an ordered list of exercises, each with its own set list. This is where the prescription attaches to the catalog.
The fluent add returning this keeps session construction readable. List.copyOf in the slot prevents later mutation of the set list, which matters once generation starts reusing sessions.
Success check: build a "Push A" session with a bench press and an overhead press, print every exercise name and its total reps. If the order matches insertion order, your list handling is correct.
Notice the session has no day attached. That separation lets you schedule the same session at different points in the week, and it lets you reuse a session across programs.
Step 4: Schedule the Week
A week is a fixed-size array of seven optional session slots, indexed 0 (Monday) through 6 (Sunday). Nulls represent rest days. A simple validation rule: no more than three consecutive training days without a rest day for beginner programs, though you can make this a configurable constraint.
The doubled loop over 14 indices is a small trick to catch runs that wrap across the week boundary. Check it: assign Monday and Sunday, and maxConsecutiveTrainingDays should return 2, not 1.
Success check: build a three-day week (Monday, Wednesday, Friday), confirm trainingDayCount() returns 3, and confirm the longest run is 1 so a beginner constraint of 2 passes.
Step 5: Capture Trainee Inputs as a Value Object
The generator needs a compact set of inputs: goal (strength, hypertrophy, general fitness), experience level, number of available days, available equipment, and current estimated 1RMs per lift. Keep this immutable and validated in the constructor.
The day range of 1–6 is a deliberate restriction: seven days leaves no rest day, and a generator that doesn't enforce recovery produces plans that look fine on paper and fail in practice. If someone needs one day, the generator should produce a full-body session rather than error.
Step 6: Write the Generator
The generator maps goal and experience to a split, filters the exercise catalog by equipment, and prescribes sets using percentage bands. Use a Random with a fixed seed for reproducible plans, or a shuffled seed for variety; either way, pass the Random in so tests can control it.
A workable prescription scheme by goal, expressed as set and rep bands:
| Goal | Sets per exercise | Reps | Effort (% of 1RM) |
|---|---|---|---|
| Strength | 3–5 | 3–5 | 80–90 |
| Hypertrophy | 3–4 | 8–12 | 65–80 |
| General | 2–3 | 10–15 | 55–70 |
These are conventional training bands, not universal truths; they're a reasonable default that your generator can expose as configuration. Write them as constants with comments so users know they're changeable.
The split selection:
For a three-day week, full body beats a push/pull/legs split because each muscle gets trained roughly three times rather than once. That's reasoning you can state in a comment, and it's a trade-off worth surfacing to users: more frequency suits beginners, more volume per session suits intermediate trainees.
The exercise selection filters by equipment and difficulty tier relative to experience, then draws without replacement per muscle group. A simple guard: if filtering leaves fewer than one exercise for a needed group, fall back to bodyweight options.
For load calculation, multiply the trainee's 1RM by the percentage and round to the nearest 2.5 kg (standard plate increments). If no 1RM is recorded for a lift, output the percentage only and label the load "estimate needed" — never invent a number.
Progression rule for a four-week block: add 2.5 kg to lower-body lifts and 1.25 kg to upper-body lifts each week at the same percentage, or add one rep per set in week three. Pick one rule and apply it consistently; mixing rules without documenting them confuses the output.
Check it: with a 100 kg squat 1RM and 80%, the result is 80.0 kg. With 77.5%, the raw value is 77.5 kg, which rounds cleanly to 77.5. Try 78%: raw is 78, which rounds to 77.5 — verify the arithmetic by hand, because this exact rounding step produces the most user complaints when it's wrong.
Step 7: Assemble and Validate the Whole Program
Wrap the generated week in a Program class that holds the block length (in weeks), the weekly template, and progression metadata. Then add a Validator that checks invariants before output:
1: Every training day has at least one exercise. 2: No muscle group is trained on more than two consecutive days. 3: Total weekly sets per muscle group land in a sane range (for example 6–20 for beginners). 4: No session prescribes a load above 95% of 1RM for more than one set.
Validation isn't decoration. Without it, a generator bug produces a plan with five leg days, and a user who doesn't know better might follow it. Run the validator in Main and print any violations before the plan itself.
Success check for the whole pipeline: give it a beginner trainee with three days, dumbbells only, and one recorded 1RM. The output should name three sessions, use only dumbbell or bodyweight exercises, show loads only for the lift with a recorded max, and pass all four validation rules.
Handling the Edge Cases That Break Naive Designs
Four situations trip up most first implementations.
Missing 1RMs. Most users won't have a tested max for every lift. Your options are to omit the load with a note, to estimate from a recent set using the Epley formula (1RM ≈ weight × (1 + reps/30)), or to prescribe reps only in week one. The Epley estimate is a formula, not a measurement — label it as an estimate and don't let it silently drive progression for a whole block.
Equipment gaps. A trainee with only bodyweight equipment will filter out barbell movements. Ensure the catalog has at least one bodyweight option in each muscle group, or the generator may throw an empty-list error. Test this combination explicitly.
More requested days than ready sessions. If the user asks for five days but your split library only covers four, the generator should either extend with a conditioning day or reduce the count and tell the user why. Silently duplicating sessions is the failure mode to avoid.
Unit confusion. If you accept pounds at the console, convert once at parse time and store kilograms. A conversion function that's called in two places is a bug waiting to happen. One entry point, one exit point.
Testing and Verifying Without a Framework
You don't need JUnit to gain confidence, though JUnit 5 is a fine addition if your build already has it. A main method that asserts expected values works for a first pass.
Write checks for the arithmetic, not the formatting. Assert that loadFor returns -1 when the 1RM is absent, that a 100 kg max at 80% yields 80.0, and that the weekly validator rejects a plan with six consecutive training days. Each assertion maps to a rule you'd otherwise have to verify by eye.
For generation, use a fixed seed and compare the full plan against an expected string. That test is brittle—it breaks whenever you change prescription bands—but it catches unintended changes during refactoring, which is exactly when you want it.
Finally, test with adversarial inputs: zero days (constructor should reject), a goal of STRENGTH with a bodyweight-only catalog (should still produce a plan), and a 1RM of 0 (should be rejected at input, not produce negative loads).
Extending the Console Program Toward an Application
Once the console version generates a correct four-week block, natural extensions open up. Persistence via JDBC or SQLite lets plans survive restarts; store exercises, sessions, and programs in normalized tables and load the catalog at startup. A REST layer over the generator turns it into a service—Spring Boot is the conventional choice, and the unchanged domain classes transfer directly. JSON output via a library like Jackson makes the plan consumable by a frontend.
What you shouldn't do is let a framework dictate the model. If ProgramGenerator depends on Spring annotations, you can't test it in a plain main. Keep the domain package free of framework imports and wrap it at the edges.
A final caution about scope: a program that computes loads and volume is a planning tool, not a coach. It can't account for sleep, injury history, or technique. Surface assumptions in the output—"assumes no injuries, 48 hours between sessions for the same muscle group"—so users know what the numbers do and don't mean.