Hello guys, can someone help me out with this simple project? [Answered]

FFaraj10/4/2022
I need to make a Running program for a user and to do that, I need to create a list of exercises. https://paste.mod.gg/yxoswdkfjnmg/1
UUUnknown User10/4/2022
Message Not Public
Sign In & Join Server To View
FFaraj10/4/2022
Ok! Since I'm a beginner, I can't build stuff on my own. This is the reason why I'm asking which's to learn new things. I have tried many times, but I just could not figure out how to solve this puzzle. So can you help out if you're experienced person?
UUUnknown User10/4/2022
2 Messages Not Public
Sign In & Join Server To View
FFaraj10/5/2022
Well! This is a simple console application that I just made up of myself so it's not a required assignment. The purpose of this project is just för practecing OOP. The goal is to make an app where the user can create an account and then choose one of the programs to train with and each program should consist of certain exercises and certain days. So this is where I got stuck.
FFaraj10/5/2022
Thank you for the link I will definitely check it
FFaraj10/5/2022
Please! I've been trying to learn how to code for a few months and I still get stuck so easily, every time I'm trying to build a simple project. Any tips on how to understand stuff and get better at it? I have a hard time modeling the real world when It comes to choosing a class, instantiation, and making an object of the class, and every time, I make a list it throws an error just like on the screeshot.
FFaraj10/5/2022
Image
FFaraj10/5/2022
The tutorials don't explain more deeply, they only explain very basic stuff.
Ppip10/5/2022
Code is largely about laziness, making things easier for yourself. The Program.cs file you linked initially has a fatal flaw : it is manually repeating information that can be automated. Not a lazy approach.

What is the difference between these blocks of code?
            Console.WriteLine("Exercise 1: Press-ups");
            var Reps1 = 10;
            var Sets1 = 2;
            if (Reps1 == 10 && Sets1 == 2)
            {
                Console.WriteLine("Do 10 reps; 2 sets and Take 5 minutes break");
            }

            Console.WriteLine("Exercise 2: Dumbbell row");
            var Reps2 = 12;
            var Sets2 = 2;
            if (Reps2 == 12 && Sets2 == 2)
            {
                Console.WriteLine("Do 12 reps on each side; 2 sets and Take 5 minutes break");
            }
Ppip10/5/2022
(i'm not quizzing you, i'm trying to explain how to think about classes + objects by guiding you through it)
FFaraj10/5/2022
Ok
Ppip10/5/2022
So what, in your mind, is the difference in content between Exercise 1 and Exercise 2
FFaraj10/5/2022
I guess only the name of the exercises and the number of the Reps & sets
Ppip10/5/2022
Correct. What is the same?
Ppip10/5/2022
if we're thinking about doing exercises, what is the same between all exercises(in the context of this code)
FFaraj10/5/2022
Well! The conditions like the Ifs + the variables
Ppip10/5/2022
Kindof, but not exactly. Think a bit deeper. What do all of these exercises have in common? Terminology wise
Ppip10/5/2022
(hint, you already told me)
FFaraj10/5/2022
I guess I'm repeating the same if conditions over and over again
Ppip10/5/2022
Reps, Sets, and Name is the same for each, right?
Ppip10/5/2022
Every exercise will have a rep, set, and a name
FFaraj10/5/2022
Yeah
Ppip10/5/2022
Guaranteed
FFaraj10/5/2022
Correct
Ppip10/5/2022
Ok, so in an object oriented manner, a lazy individual like myself would observe this pattern: the pattern that all exercises have these variables, and all of these variables can be different. I would write

class Exercise
{
  public string Name {get;set;}
  public int Sets {get;set;}
  public int Reps {get;set;}
}
Ppip10/5/2022
Now how do I differentiate Situps from Pushups?
Ppip10/5/2022
Exercise pushups = new Exercise();
pushups.Name = "pushups";
pushups.Sets = 10;
pushups.Reps = 2;

Exercise situps = new Exercise();
situps.Name = "situps";
situps.Sets = 15;
situps.Reps = 2;
Ppip10/5/2022
both situps and pushups have one thing in commons always -> they're exercises.
Ppip10/5/2022
Now let's say that another variable an exercise has is not only how many sets/reps we have to do, but also where the user currently is(which set/rep they are on when going through each exercise)
Ppip10/5/2022
How would you add these variables?
FFaraj10/5/2022
OMG, you're great bro at explaining things.
Ppip10/5/2022
not done yet, there's a little bit more to wrap your head around
Ppip10/5/2022
how would you add the variables(just making sure we're on the same page)
FFaraj10/5/2022
Well! I guess we can use the swith statements or the break I don't know.
Ppip10/5/2022
it's even easier than that
FFaraj10/5/2022
We stop looping by using break
Ppip10/5/2022
we aren't at loops yet, just defining exercises
Ppip10/5/2022
so this is how you would do it
FFaraj10/5/2022
Ok
Ppip10/5/2022
class Exercise
{
  public string Name {get;set;}
  public int Sets {get;set;}
  public int Reps {get;set;}
  public int CurrentSets {get;set;}
  public int CurrentReps {get;set;}
}
Ppip10/5/2022
Because sets + reps by themselves only define the max number of actions you can do right?
Ppip10/5/2022
You could do a loop as well instead of this I suppose, but let's just do this for now
FFaraj10/5/2022
Yeah
FFaraj10/5/2022
But why should I think that the user will do more reps and sets?
FFaraj10/5/2022
Shouldn't I defind only a limited range of reps and sets?
FFaraj10/5/2022
Like for example a 10 for each and that's it
Ppip10/5/2022
Right, "Sets" and "Reps" both define the MAX number of reps/sets that a user does right? But in the example I'm giving you, we want to keep track of each rep + set that the user does OK?
Ppip10/5/2022
That's where CurrentSets and CurrentReps come in
Ppip10/5/2022
So if Pushups is 10 sets and 2 reps, CurrentSets and CurrentReps will starts at 0 when we start
FFaraj10/5/2022
Although your method of creating the project would be a good practice
FFaraj10/5/2022
yes
Ppip10/5/2022
Ok. so we define exercises as ONLY a name, reps, sets, and some other stuff. So an exercise is just reps + sets basically. Is there a difference in how you advance your "CurrentSets" and "CurrentReps" in situps/pushups if they're both exercises?
FFaraj10/5/2022
I'm thinknig
FFaraj10/5/2022
No
FFaraj10/5/2022
Can I please call you
Ppip10/5/2022
Exactly. Because really, in the context of our program, we only care about a few things
Ppip10/5/2022
I'm at work right now so I don't think I can atm
FFaraj10/5/2022
Ah! Ok! It's alright.
Ppip10/5/2022
maybe later though if you still need help
Ppip10/5/2022
Ok, but you're right, there's no difference
Ppip10/5/2022
So with that in mind, since they're both exercises and both operate in the same way,
class Exercise
{
  public string Name {get;set;}
  public int Sets {get;set;}
  public int Reps {get;set;}
  public int CurrentSets {get;set;}
  public int CurrentReps {get;set;}

  public void DoSet()
  {
    
  } 
   
}
FFaraj10/5/2022
Ok! Thanks
Ppip10/5/2022
and then you can write your logic ONCE that applies for every exercise
Ppip10/5/2022
Boom, object orientation
FFaraj10/5/2022
Wow! Great.
Ppip10/5/2022
so in your Program.cs, you wrote logic 10 times. Imagine if that number were 100, it's not sustainable. One and done should be your goal whenever you're making something, try to find ways to simplify it and make it as easy as possible to replicate.
Ppip10/5/2022
let me know if you have any more questions
FFaraj10/5/2022
You're absloutly right
FFaraj10/5/2022
Ok
Ppip10/5/2022
And now that you have this context, take a look at the code that @Lurch sent you
FFaraj10/5/2022
List<Activities> programList = new List<Activities>();


            programList.Add(new Activities("Running", 60));
            programList.Add(new Activities("Workout", 50));
            programList.Add(new Activities("Yoga", 20));
            programList.Add(new Activities("Swimming", 45));
FFaraj10/5/2022
I made these, do you think I could grab one of these programs in order to make a program like Running program?
FFaraj10/5/2022
Is this the right way to do it?
Ppip10/5/2022
That looks great, much better than the Program.cs you linked before
Ppip10/5/2022
you may have to pass more parameters through each Activities constructor, but its a good start
FFaraj10/5/2022
It's the same
Ppip10/5/2022
Ohhh I'm more referring to like line 100+
FFaraj10/5/2022
Ok
FFaraj10/5/2022
Yes you did
Ppip10/5/2022
ok
Ppip10/5/2022
so each activity has exercises yes?
FFaraj10/5/2022
Yes
Ppip10/5/2022
using the code I have above you can do something like
public class Activity
{
  public string Name {get;set;}
  public List<Exercise> Exercises {get;set;}
}
FFaraj10/5/2022
Ok
Ppip10/5/2022
Because each activity has its own exercises, each exercise has its own reps/sets right?
FFaraj10/5/2022
Yes
FFaraj10/5/2022
You're right
FFaraj10/5/2022
So we could create a list from the proporties?
FFaraj10/5/2022
We usually create a list when we make a new opbject right?
Ppip10/5/2022
Yup you can have a list in your properties, you can have anything in your properties
Ppip10/5/2022
yea actually you can probably just do
public List<Exercise> Exercises = new();
instead to initialize it
FFaraj10/5/2022
Ok! But why do people make a list in the Program.cs
Ppip10/5/2022
then do add stuff, you can do
Activity activity = new Activity(); 
activity.Exercises.Add(new Exercise(/*blah blah blah*/));
FFaraj10/5/2022
And not in the properties
Ppip10/5/2022
well it depends on what you're doing
Ppip10/5/2022
because a list of activities isn't in the properties of an object somewhere right?
FFaraj10/5/2022
Ok
Ppip10/5/2022
so you'll have to make that somewhere else, not in a class