Workout program progression - Ways to make my Java program shorter/smarter?
Introduction:
Hi, I just made this program. [Java] Wendler - Pastebin.com (It's kinda long, so I figured it was better to upload it to pastebin)
What it's for: [Moderator edit: link removed]
This powerlifting program is structured so you have to workout with %'s of your max lift(the maximum weight you can lift for one repetition). First it cuts your max down to 90% of its initial value. And then all the different percentages is made calculating with the new "max" value.
Etc. I lift 200kg in deadlift for max, and have to know what weight I should use if the program dictates 60% in the workout set I'm about to do. Then first 90% of 200kg, which is 180kg, and then 60% of 180kg, which is 108kg. Then 108 is the number it should print out together with the other numbers for the other lifts for that workout.
The reason to make a program for these calculations, is that after every cyclus consisting of 4 weeks, you will repeat the program, but adding 2,5kg to your initial benchpress- and shoulderpress max, and adding 5kg to your initial deadlift- and squat max.
So with this program you just type in your max for the 4 different lifts, and adjust the value which "i" should be equal or less than in the for loop, for the amount of cyclusses you want.
So in cyclus 10 your lifts should be clearly heavier than in the first one.
I think it will make most sense, if you try to run the program, and see the outprint.
Questions:
Declaring all the double variables first, was a waste of time right? Since I didn't use any of them more than once, and I could just had made the calculations for each set in the println. statement.
And is there any smarter way, than to actually make a new println. statement for each single set? Maybe a nested for loop somehow?
Also I want the numbers in the outprint to be rounded up or down to numbers in a 2,5 number table. Because I can't add weight on a barbell so I get between those 2,5 jumps anyway. Like if the outprint is 66,8 I want it to make it to 67,5 automatically. Or if it's 55,333333, it should just be 55. How do I do this? (my guess would be to use Math.round somehow)
And the last question, would it be easy to create a scanner, so when I run the program, I will be asked what my max in all 4 lifts is, and how many cyclusses I want outprint for? So it's a bit more user friendly, if I should share the program with others.
Re: Workout program progression - Ways to make my Java program shorter/smarter?
Your current code:
Code:
public class Wendler {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
// declaring current max lifts
double deadliftMax = 220 + (i * 5) - 5;
double squatMax = 140 + (i * 5) - 5;
double shoulderMax = 100 + (i * 2.5) - 2.5;
double benchpressMax = 100 + (i * 2.5) - 2.5;
// FIRST WEEK
// calculating lifts for first cyclus first week - Deadlift
double week1set1deadlift = (deadliftMax * 0.9) * 0.65;
double week1set2deadlift = (deadliftMax * 0.9) * 0.75;
double week1set3deadlift = (deadliftMax * 0.9) * 0.85;
// calculating lifts for first cyclus first week - Squat
double week1set1squat = (squatMax * 0.9) * 0.65;
double week1set2squat = (squatMax * 0.9) * 0.75;
double week1set3squat = (squatMax * 0.9) * 0.85;
// calculating lifts for first cyclus first week - Shoulder
double week1set1shoulder = (shoulderMax * 0.9) * 0.65;
double week1set2shoulder = (shoulderMax * 0.9) * 0.75;
double week1set3shoulder = (shoulderMax * 0.9) * 0.85;
// calculating lifts for first cyclus first week - Benchpress
double week1set1benchpress = (benchpressMax * 0.9) * 0.65;
double week1set2benchpress = (benchpressMax * 0.9) * 0.75;
double week1set3benchpress = (benchpressMax * 0.9) * 0.85;
// SECOND WEEK
// calculating lifts for first cyclus second week - Deadlift
double week2set1deadlift = (deadliftMax * 0.9) * 0.70;
double week2set2deadlift = (deadliftMax * 0.9) * 0.80;
double week2set3deadlift = (deadliftMax * 0.9) * 0.90;
// calculating lifts for first cyclus second week - Squat
double week2set1squat = (squatMax * 0.9) * 0.70;
double week2set2squat = (squatMax * 0.9) * 0.80;
double week2set3squat = (squatMax * 0.9) * 0.90;
// calculating lifts for first cyclus second week - Shoulder
double week2set1shoulder = (shoulderMax * 0.9) * 0.70;
double week2set2shoulder = (shoulderMax * 0.9) * 0.80;
double week2set3shoulder = (shoulderMax * 0.9) * 0.90;
// calculating lifts for first cyclus second week - Benchpress
double week2set1benchpress = (benchpressMax * 0.9) * 0.70;
double week2set2benchpress = (benchpressMax * 0.9) * 0.80;
double week2set3benchpress = (benchpressMax * 0.9) * 0.90;
// THIRD WEEK
// calculating lifts for first cyclus third week - Deadlift
double week3set1deadlift = (deadliftMax * 0.9) * 0.75;
double week3set2deadlift = (deadliftMax * 0.9) * 0.85;
double week3set3deadlift = (deadliftMax * 0.9) * 0.95;
// calculating lifts for first cyclus third week - Squat
double week3set1squat = (squatMax * 0.9) * 0.75;
double week3set2squat = (squatMax * 0.9) * 0.85;
double week3set3squat = (squatMax * 0.9) * 0.95;
// calculating lifts for first cyclus third week - Shoulder
double week3set1shoulder = (shoulderMax * 0.9) * 0.75;
double week3set2shoulder = (shoulderMax * 0.9) * 0.85;
double week3set3shoulder = (shoulderMax * 0.9) * 0.95;
// calculating lifts for first cyclus third week - Benchpress
double week3set1benchpress = (benchpressMax * 0.9) * 0.75;
double week3set2benchpress = (benchpressMax * 0.9) * 0.85;
double week3set3benchpress = (benchpressMax * 0.9) * 0.95;
// FOURTH WEEK
// calculating lifts for first cyclus fourth week - Deadlift
double week4set1deadlift = (deadliftMax * 0.9) * 0.40;
double week4set2deadlift = (deadliftMax * 0.9) * 0.50;
double week4set3deadlift = (deadliftMax * 0.9) * 0.60;
// calculating lifts for first cyclus fourth week - Squat
double week4set1squat = (squatMax * 0.9) * 0.40;
double week4set2squat = (squatMax * 0.9) * 0.50;
double week4set3squat = (squatMax * 0.9) * 0.60;
// calculating lifts for first cyclus fourth week - Shoulder
double week4set1shoulder = (shoulderMax * 0.9) * 0.40;
double week4set2shoulder = (shoulderMax * 0.9) * 0.50;
double week4set3shoulder = (shoulderMax * 0.9) * 0.60;
// calculating lifts for first cyclus fourth week - Benchpress
double week4set1benchpress = (benchpressMax * 0.9) * 0.40;
double week4set2benchpress = (benchpressMax * 0.9) * 0.50;
double week4set3benchpress = (benchpressMax * 0.9) * 0.60;
// Deadlift
System.out.println("-----------------------------------");
System.out.println("Cyclus " + i + " Week 1 - Deadlift");
System.out.println(week1set1deadlift);
System.out.println(week1set2deadlift);
System.out.println(week1set3deadlift);
System.out.println();
System.out.println("Cyclus " + i + " Week 2 - Deadlift");
System.out.println(week2set1deadlift);
System.out.println(week2set2deadlift);
System.out.println(week2set3deadlift);
System.out.println();
System.out.println("Cyclus " + i + " Week 3 - Deadlift");
System.out.println(week3set1deadlift);
System.out.println(week3set2deadlift);
System.out.println(week3set3deadlift);
System.out.println();
System.out.println("Cyclus " + i + " Week 4 - Deadlift");
System.out.println(week4set1deadlift);
System.out.println(week4set2deadlift);
System.out.println(week4set3deadlift);
System.out.println();
// Squat
System.out.println("-----------------------------------");
System.out.println("Cyclus " + i + " Week 1 - Squat");
System.out.println(week1set1squat);
System.out.println(week1set2squat);
System.out.println(week1set3squat);
System.out.println();
System.out.println("Cyclus " + i + " Week 2 - Squat");
System.out.println(week2set1squat);
System.out.println(week2set2squat);
System.out.println(week2set3squat);
System.out.println();
System.out.println("Cyclus " + i + " Week 3 - Squat");
System.out.println(week3set1squat);
System.out.println(week3set2squat);
System.out.println(week3set3squat);
System.out.println();
System.out.println("Cyclus " + i + " Week 4 - Squat");
System.out.println(week4set1squat);
System.out.println(week4set2squat);
System.out.println(week4set3squat);
System.out.println();
// Shoulder
System.out.println("-----------------------------------");
System.out.println("Cyclus " + i + " Week 1 - Shoulderpress");
System.out.println(week1set1shoulder);
System.out.println(week1set2shoulder);
System.out.println(week1set3shoulder);
System.out.println();
System.out.println("Cyclus " + i + " Week 2 - Shoulderpress");
System.out.println(week2set1shoulder);
System.out.println(week2set2shoulder);
System.out.println(week2set3shoulder);
System.out.println();
System.out.println("Cyclus " + i + " Week 3 - Shoulderpress");
System.out.println(week3set1shoulder);
System.out.println(week3set2shoulder);
System.out.println(week3set3shoulder);
System.out.println();
System.out.println("Cyclus " + i + " Week 4 - Shoulderpress");
System.out.println(week4set1shoulder);
System.out.println(week4set2shoulder);
System.out.println(week4set3shoulder);
System.out.println();
// Benchpress
System.out.println("-----------------------------------");
System.out.println("Cyclus " + i + " Week 1 - Benchpress");
System.out.println(week1set1benchpress);
System.out.println(week1set2benchpress);
System.out.println(week1set3benchpress);
System.out.println();
System.out.println("Cyclus " + i + " Week 2 - Benchpress");
System.out.println(week2set1benchpress);
System.out.println(week2set2benchpress);
System.out.println(week2set3benchpress);
System.out.println();
System.out.println("Cyclus " + i + " Week 3 - Benchpress");
System.out.println(week3set1benchpress);
System.out.println(week3set2benchpress);
System.out.println(week3set3benchpress);
System.out.println();
System.out.println("Cyclus " + i + " Week 4 - Benchpress");
System.out.println(week4set1benchpress);
System.out.println(week4set2benchpress);
System.out.println(week4set3benchpress);
System.out.println();
}
}
}
Oh, there's a lot you could do to improve that code, including,
- most importantly, to get it out of static land and into OOP land by creating oop-compliant classes that work well together.
- For example you could create an Exercise class with a String field for exerciseName, a double for maxWeight, and a double array for repMultipliers (which in your case would be filled with {0.65, 0.75, 0.85} but which can be changed when desired). You could give it a formattedOutput() method that returns a String showing the current weight for the exercise formatted with a DecimalFormat to show however many values past the decimal point that you desire.
- And you could create an ExerciseRegime class that holds an ArrayList of Exercise objects. In this you could create your Exercise objects and set their values, and create loops for each week where you'd change your values.
- The next key thing to do is to find all code that looks repetitive (and there's a lot), and consolidating it into classes and methods. Look into using arrays or ArrayList for holding similar types of information.
- Next look at where you may be hard-coding numbers and change them to either constants (for readability) or variables (for flexibility). The former make your code self-documenting and more adaptable, such that you can change a constant's value at a later date and not have to change numbers throughout the program. The latter allows your program to dynamically change the values since that values that work well for your work-out schedule might not work well for others.
Re: Workout program progression - Ways to make my Java program shorter/smarter?
Hey thanks for answer, just the kind of answer I was looking for :) Will update when I have made it better.
Re: Workout program progression - Ways to make my Java program shorter/smarter?
You're welcome, and best of luck!
Re: Workout program progression - Ways to make my Java program shorter/smarter?
Finally got time to finish this program. Well still with room for a lot of improvements, but I feel that it's gotten better than my last attempt(the first one in this thread).
There is still things I want to do with this program, that I couldn't figure out.
How do I round all the numbers for weight to the nearest 2.5 multiple(because you can't load a barbell with 34,8kg etc. that should be 35kg, like 36.9kg should be 37.5kg)?
Also I want to move the whole method into a class of it's own, and make the main class use that instead of the current static method.
I tried by copy/paste the whole method into a new class that I called Lift. I removed the "public static void lift(double lift, double prog, int cyclus, String type) {" part, and just wrote "double lift, double prog, int cyclus, String type;" instead.
Then in main(Wendler2) I wrote Lift a = new Lift, and then a.Lift instead of just list at the System.out.println part of main.
Didn't work, will tell in this thread if I succeeds to make it work.
Code:
public class Wendler2 {
public static void main(String[] args) {
//declare max lift in kg
double shoulderpress = 95;
double benchpress = 150;
double deadlift = 230;
double squat = 145;
String sho = "Shoulderpres";
String ben = "Benchpress";
String dea = "Deadlift";
String squ = "Squat";
//declare progression for each cyclus in kg, and amount of cyclusses.
double prog1 = 2.5;
double prog2 = 5;
int cyclus = 10;
System.out.println("Jim Wendler 5/3/1");
//Print out list of initial max lifts for all 4 lifts
System.out.println("Your chosen max lifts for first cyclus are:\nShoulderpress = " + shoulderpress + "\nBenchpress = " + benchpress + "\nDeadlift = " + deadlift + "\nSquat = " + squat + "\n");
//Use method "lift" to print out for each of the 4 lifts
System.out.println("-----SHOULDERPRESS----- \n");
lift(shoulderpress, prog1, cyclus, sho);
System.out.println("-----BENCHPRESS----- \n");
lift(benchpress, prog1, cyclus, ben);
System.out.println("-----DEADLIFT----- \n");
lift(deadlift, prog2, cyclus, dea);
System.out.println("-----SQUAT----- \n");
lift(squat, prog2, cyclus, squ);
}
//Method for calculating and printing lifts
public static void lift(double lift, double prog, int cyclus, String type) {
for (int i = 1 ; i <= cyclus ; i++) {
double max = lift+(i*prog)-prog;
String kg = " kg";
System.out.println("Cyclus " + i +"\n");
//first week
System.out.println("Week 1 " + type + "\n");
System.out.println("set 1: 5 x " + (max*0.9)*0.65 + kg);
System.out.println("set 2: 5 x " + (max*0.9)*0.75 + kg);
System.out.println("set 3: 5+ x " + (max*0.9)*0.85 + kg + "\n");
//second week
System.out.println("Week 2 " + type + "\n");
System.out.println("set 1: 3 x " + (max*0.9)*0.70 + kg);
System.out.println("set 2: 3 x " + (max*0.9)*0.80 + kg);
System.out.println("set 3: 3+ x " + (max*0.9)*0.90 + kg + "\n");
//third week
System.out.println("Week 3 " + type + "\n");
System.out.println("set 1: 5 x " + (max*0.9)*0.75 + kg);
System.out.println("set 2: 3 x " + (max*0.9)*0.85 + kg);
System.out.println("set 3: 1+ x " + (max*0.9)*0.95 + kg + "\n");
//fourth week
System.out.println("Week 4 " + type + "\n");
System.out.println("set 1: 5 x " + (max*0.9)*0.40 + kg);
System.out.println("set 2: 5 x " + (max*0.9)*0.50 + kg);
System.out.println("set 3: 5 x " + (max*0.9)*0.60 + kg +"\n");
}
}
}