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

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
BlazeBin - yxoswdkfjnmg
A tool for sharing your source code with the world!
342 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The king of kings
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?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The king of kings
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. Thank you for the link I will definitely check it 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.
The king of kings
The tutorials don't explain more deeply, they only explain very basic stuff.
pip
pip3y ago
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");
}
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");
}
(i'm not quizzing you, i'm trying to explain how to think about classes + objects by guiding you through it)
The king of kings
Ok
pip
pip3y ago
So what, in your mind, is the difference in content between Exercise 1 and Exercise 2
The king of kings
I guess only the name of the exercises and the number of the Reps & sets
pip
pip3y ago
Correct. What is the same? if we're thinking about doing exercises, what is the same between all exercises(in the context of this code)
The king of kings
Well! The conditions like the Ifs + the variables
pip
pip3y ago
Kindof, but not exactly. Think a bit deeper. What do all of these exercises have in common? Terminology wise (hint, you already told me)
The king of kings
I guess I'm repeating the same if conditions over and over again
pip
pip3y ago
Reps, Sets, and Name is the same for each, right? Every exercise will have a rep, set, and a name
The king of kings
Yeah
pip
pip3y ago
Guaranteed
The king of kings
Correct
pip
pip3y ago
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;}
}
class Exercise
{
public string Name {get;set;}
public int Sets {get;set;}
public int Reps {get;set;}
}
Now how do I differentiate Situps from Pushups?
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;
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;
both situps and pushups have one thing in commons always -> they're exercises. 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) How would you add these variables?
The king of kings
OMG, you're great bro at explaining things.
pip
pip3y ago
not done yet, there's a little bit more to wrap your head around how would you add the variables(just making sure we're on the same page)
The king of kings
Well! I guess we can use the swith statements or the break I don't know.
pip
pip3y ago
it's even easier than that
The king of kings
We stop looping by using break
pip
pip3y ago
we aren't at loops yet, just defining exercises so this is how you would do it
The king of kings
Ok
pip
pip3y ago
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;}
}
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;}
}
Because sets + reps by themselves only define the max number of actions you can do right? You could do a loop as well instead of this I suppose, but let's just do this for now
The king of kings
Yeah But why should I think that the user will do more reps and sets? Shouldn't I defind only a limited range of reps and sets? Like for example a 10 for each and that's it
pip
pip3y ago
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? That's where CurrentSets and CurrentReps come in So if Pushups is 10 sets and 2 reps, CurrentSets and CurrentReps will starts at 0 when we start
The king of kings
Although your method of creating the project would be a good practice yes
pip
pip3y ago
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?
The king of kings
I'm thinknig No Can I please call you
pip
pip3y ago
Exactly. Because really, in the context of our program, we only care about a few things I'm at work right now so I don't think I can atm
The king of kings
Ah! Ok! It's alright.
pip
pip3y ago
maybe later though if you still need help Ok, but you're right, there's no difference 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()
{

}

}
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()
{

}

}
The king of kings
Ok! Thanks
pip
pip3y ago
and then you can write your logic ONCE that applies for every exercise Boom, object orientation
The king of kings
Wow! Great.
pip
pip3y ago
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. let me know if you have any more questions
The king of kings
You're absloutly right Ok
pip
pip3y ago
And now that you have this context, take a look at the code that @Lurch sent you
The king of kings
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));
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));
I made these, do you think I could grab one of these programs in order to make a program like Running program? Is this the right way to do it?
pip
pip3y ago
That looks great, much better than the Program.cs you linked before you may have to pass more parameters through each Activities constructor, but its a good start
The king of kings
It's the same
pip
pip3y ago
Ohhh I'm more referring to like line 100+
The king of kings
Ok Yes you did
pip
pip3y ago
ok so each activity has exercises yes?
The king of kings
Yes
pip
pip3y ago
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;}
}
public class Activity
{
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
The king of kings
Ok
pip
pip3y ago
Because each activity has its own exercises, each exercise has its own reps/sets right?
The king of kings
Yes You're right So we could create a list from the proporties? We usually create a list when we make a new opbject right?
pip
pip3y ago
Yup you can have a list in your properties, you can have anything in your properties yea actually you can probably just do
public List<Exercise> Exercises = new();
public List<Exercise> Exercises = new();
instead to initialize it
The king of kings
Ok! But why do people make a list in the Program.cs
pip
pip3y ago
then do add stuff, you can do
Activity activity = new Activity();
activity.Exercises.Add(new Exercise(/*blah blah blah*/));
Activity activity = new Activity();
activity.Exercises.Add(new Exercise(/*blah blah blah*/));
The king of kings
And not in the properties
pip
pip3y ago
well it depends on what you're doing because a list of activities isn't in the properties of an object somewhere right?
The king of kings
Ok
pip
pip3y ago
so you'll have to make that somewhere else, not in a class
The king of kings
Yes
pip
pip3y ago
Ok cool, study what the other guy sent you and think about what I said, give it a go. if you have any questions about something let me know
The king of kings
I will definitely do it, thank you so much for all the learning content and the code model that you provided me, I really appreciate man 🙏 🙂
pip
pip3y ago
no problem 😄 good luck
The king of kings
Hello there, just to make things more clear. You have mentioned two differnt modules of code, so the question is, which one should I use? this one
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()
{

}

}
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()
{

}

}
or this one
Activity activity = new Activity();
activity.Exercises.Add(new Exercise(/*blah blah blah*/));
Activity activity = new Activity();
activity.Exercises.Add(new Exercise(/*blah blah blah*/));
I got a bit confused
pip
pip3y ago
these are different yes, but are these codeblocks describing the same thing?(meaning you must choose one or ther other), or do they compliment eachother? also, Lurch linked you some code that could suffice as a point to start learning from you don't necessarily have to take what I wrote, you can take either my concepts or his. but his are better fleshed out
The king of kings
Aha! Ok! So yours is just a susggestion, based on the project pattern. I have looked at his code modul, but ut seems advanced and he is using code that I haven't seen before. I don't know, it seems like he is using almost a totally different approach from what I have built.
pip
pip3y ago
he does add a few things and use some advanced concepts that is true. yea what I've given you is mainly a suggestion, but you could probably also just use it
The king of kings
Yes he really does, I think your code much easier, but to try out his code, could be a good practice to learn a new concepts. I just wanna ask you this, how am I gonna create the these programs/ activities in your code module? Like running, swimming, workout and bicycling and then create a program which consist of a veriuos of exercises for each of these programs? Is this for the programs/ activities?
public string Name { get; set; }
public string Name { get; set; }
pip
pip3y ago
the only difference between activities is their name, and the exercises in the activity
public class Activity
{
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
public class Activity
{
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
let's add a constructor to make it easy
public class Activity
{
public Activity(string newName)
{
Name = newName;
}
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
public class Activity
{
public Activity(string newName)
{
Name = newName;
}
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
then when using this class in your program, we can do
List<Exercise> exercises = new List<Exercise>();
//add exercises to this list
Activity swimming = new Activity("swimming");
swimming.Exercises = exercises;

//now your activity has a name, and exercises
List<Exercise> exercises = new List<Exercise>();
//add exercises to this list
Activity swimming = new Activity("swimming");
swimming.Exercises = exercises;

//now your activity has a name, and exercises
The king of kings
Awesome Now things is getting very clear and I do understand a lot from these code examples in above. So instead of the exercises word should I fill up the exercises? Or should I add them somewhere else? Like the name of the exercises followed with the Reps & sets // 1. Kick Drills, 2. Breaststroke and Butterfly Drill, 3. Water Running // these are exercises for the swimming by the way.
pip
pip3y ago
Exercises are objects, so you have to instantiate them
List<Exercise> exercises = new List<Exercise>();

//create exercise
Exercise pushups = new Exercise();
pushups.Name = "pushups";
pushups.Sets = 10;
pushups.Reps = 2;
//add exercise to list
exercises.Add(pushups);

//create activity
Activity swimming = new Activity("swimming");

//assign exercises to activity
swimming.Exercises = exercises;
List<Exercise> exercises = new List<Exercise>();

//create exercise
Exercise pushups = new Exercise();
pushups.Name = "pushups";
pushups.Sets = 10;
pushups.Reps = 2;
//add exercise to list
exercises.Add(pushups);

//create activity
Activity swimming = new Activity("swimming");

//assign exercises to activity
swimming.Exercises = exercises;
The king of kings
I just wanna check one thing! Based on the code examples that you provided me, I see that we have two different classes? class Activity & class Exercise, right?
public class Activity
{
public Activity(string newName)
{
Name = newName;
}
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
public class Activity
{
public Activity(string newName)
{
Name = newName;
}
public string Name {get;set;}
public List<Exercise> Exercises {get;set;}
}
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()
{

}

}
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()
{

}

}
And we compliment/ referance each other in this code
List<Exercise> exercises = new List<Exercise>();

//create exercise
Exercise pushups = new Exercise();
pushups.Name = "pushups";
pushups.Sets = 10;
pushups.Reps = 2;
//add exercise to list
exercises.Add(pushups);

//create activity
Activity swimming = new Activity("swimming");

//assign exercises to activity
swimming.Exercises = exercises;
List<Exercise> exercises = new List<Exercise>();

//create exercise
Exercise pushups = new Exercise();
pushups.Name = "pushups";
pushups.Sets = 10;
pushups.Reps = 2;
//add exercise to list
exercises.Add(pushups);

//create activity
Activity swimming = new Activity("swimming");

//assign exercises to activity
swimming.Exercises = exercises;
I just got a little confused and tried to understand the code that you wrote Sorry for asking many questions about the same code and not understanding evereything
pip
pip3y ago
an Activity is a thing. an Exercise is a thing. whenever you think "this is a thing", it's an object and probably merits its own class. class Dog, class Animal, class Bike, class Car Activities are things that have Exercises(in your project) so we're storing a list, a "collection" of exercises in the activity
The king of kings
Ok
pip
pip3y ago
much like how an "arm" is a thing, a "human" is a thing, when you're making class Human you'll want to have it contain an "Arm"
class Human
{
public Arm HumanArm {get;set;}
}
class Human
{
public Arm HumanArm {get;set;}
}
The king of kings
Yes, that's right.
pip
pip3y ago
Ok, so I'm creating exercises, because they're things(objects) that have properties. I'm adding them to a collection. when I fill the collection, I'll store it in the activity. and somewhere along the way i'll make the Activity itself too
The king of kings
Ok! Got it. Yeah! Like class Car object myCar, Class Book object myBook. When you instansiate the object myCar then you're asigning values to the properties of the class Car So my project is almost similer to these examples where I have a class Activity, Name & Exercises is the property and exercises is the object, right?
pip
pip3y ago
exercise is an object that you're adding to the "list object" exercises. then you're copying the "list object" to the list Exercises, which is a property. you are correct
The king of kings
Great Do you what confused mostly? Where are using a different name convention. I would use like class Activity, Exercises as property and myExerciseProgram as object, you know I'm saying. But then we have a multiple programs for the activity, which is runningProgram, swimmingProgram and etc...
pip
pip3y ago
You can organize your class hierarchy in a way that fits your program, so maybe instead of nesting "Exercises" in Activity, you can nest Exercises in Program. Then you can have multiple programs in an activity, etc.
pip
pip3y ago
C# Coding Conventions
Learn about coding conventions in C#. Coding conventions create a consistent look to the code and facilitate copying, changing, and maintaining the code.
The king of kings
And each program consist of a verious exercises Yeah! You're right. This is exactly what I'm talking about. Lets say we mimic one of the real Fittnes apps on our iphones. The goal of the app is that the user will open the app and would have a manu of several activities displyed on the screen. The user will click on one of the activities like "Running" in this case the app should display a "Running program" for the user and the program contains a list of exercises that he needs to train to be able to become an elite runner. The same idea applies for the other activities like swimming, workout and bycicling. I hope I didn't confuse you with a lot of details.
pip
pip3y ago
That's perfectly clear to me
The king of kings
Great to hear that
pip
pip3y ago
I think you have enough information to construct that yourself though, using the same principles we went over with nesting object arrays(or lists) inside of classes as properties 😄
The king of kings
Yes, I will try to build the project and see where I end up. Then I would like to send you a copy just for evaluation 🤗
pip
pip3y ago
ok sounds good 👍
The king of kings
Thanks This project might look simple, but it's really a paining in the ass 😂
The king of kings
Please take a look on what I've built https://paste.mod.gg/ejylknvjbfsk/2
BlazeBin - ejylknvjbfsk
A tool for sharing your source code with the world!
The king of kings
I hope I git it right, although there are many errors 🤷🏻‍♂️
pip
pip3y ago
it looks OK so far, you're probably going to have to move your exercise class outside of the activity class though
The king of kings
You mean, I need to create a new class called "public class Exercise"?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The king of kings
Ok! Here is the updated version. https://paste.mod.gg/nxitcauurcce/2
BlazeBin - nxitcauurcce
A tool for sharing your source code with the world!
pip
pip3y ago
Still need to move class Exercise out of class Activity pepecoffee make an Exercise.cs file and move your class code to that file and make it public
The king of kings
One problem, I face every time, I make a list for an object, is that it always throws an error like in the above code,
The king of kings
What, I already did, it's in a new class file.
The king of kings
Look Oh! Sorry, I forgot to edit the code in the BlazeBin.
pip
pip3y ago
ah ok read that exception though, i'm certain you can find what's wrong
The king of kings
BlazeBin - qlcjojvtkhcm
A tool for sharing your source code with the world!
The king of kings
Now it's ready to be reviewed.
pip
pip3y ago
there is no argument found that corresponds to parameter called name
The king of kings
Ok! Well! Look, it's giving me a solution which is making a constructer, but I have already a constructer, why should I have a double.
The king of kings
Ok!It always says the same.
pip
pip3y ago
is there anything in your constructor? the one that exists currently?
The king of kings
I do have a constructer that contains parameters 🤷🏻‍♂️
pip
pip3y ago
so with this in mind, what's missing when you're initializing your Exercise object?
The king of kings
Well! I guess arguments are missing. Right? Ah! Ok! Wait minute.
pip
pip3y ago
yup
The king of kings
I think I know what is missing I forgot what it's called I will get back to you soon, after I figure out exactly what is missing.
pip
pip3y ago
this is what is missing, you already got it you need to pass arguments into your constructor
The king of kings
Well! Not only that. I have thought about something else too. I usually do it every time I make an object
// create exercise
Exercise kickDrills = new Exercise();
kickDrills.Name = "Kick Drills";
kickDrills.Sets = 10;
kickDrills.Reps = 2;
//kickDrills.CurrentSets =
//kickDrills.CurrentSets =
Console.WriteLine("{0} {1} {2} {3}",
kickDrills.Name,
kickDrills.Sets,
kickDrills.Reps);
// create exercise
Exercise kickDrills = new Exercise();
kickDrills.Name = "Kick Drills";
kickDrills.Sets = 10;
kickDrills.Reps = 2;
//kickDrills.CurrentSets =
//kickDrills.CurrentSets =
Console.WriteLine("{0} {1} {2} {3}",
kickDrills.Name,
kickDrills.Sets,
kickDrills.Reps);
I guess this didn't really solve the problem 😆 But I know what the solution is Inside the parentheses of kickDrills, I need to pass the arguments. Right? For example!
The king of kings
BlazeBin - vhaqpnydhizk
A tool for sharing your source code with the world!
The king of kings
That's strange 🤔 Still the arguments issue appears, although I had to modify the code.
pip
pip3y ago
you have to pass each and every argument you specified in the exercise you probably dont need the currensets + currentreps constructor params so remove those parameters and see if it works
The king of kings
Yep, you were totally right. The error just disappeared forever 😀 But in this code only the exercise is defined, but I didn't set it to any of the activities for example "swimming"! Shouldn't this code be swimming object instead of just exercise?
List<Exercise> exercises = new List<Exercise>();
List<Exercise> exercises = new List<Exercise>();
pip
pip3y ago
you can do swimming.Exercises = new List<Exercise>(); and add your exercises that way if helps it make more sense then swimming.Exercises.Add(//your code here); to add them
The king of kings
Ok! It didn't work actually. Because I had an error saying there are no arguments corresponding bla bla so I had to pass the parameters and this is what I end up doing.
List<Exercise> exercises = new List<Exercise>();
// create exercises
Exercise pressUps = new Exercise("Exercise 1: Press-ups kick Drills", 10, 2);
Exercise DumbbellRow = new Exercise("Exercise 2: Dumbbell row", 12, 2);
Exercise TricepDips = new Exercise("Exercise 3: Tricep dips", 12, 2);
Exercise StepUps = new Exercise("Exercise 4: Step-ups", 10, 2);
Exercise Squats = new Exercise("Exercise 5: Squats", 15, 2);
Exercise WalkingLunges = new Exercise("Exercise 6: Walking lunges", 8, 2);
Exercise SingleLegDeadLift = new Exercise("Exercise 7: Single-leg deadlift", 10, 2);
Exercise SupermanBackExtension = new Exercise("Exercise 8: Superman/back extension", 10, 2);
Exercise Glutebridge = new Exercise("Exercise 9: Glute bridge", 15, 2);
Exercise LegRaises = new Exercise("Exercise 10: Leg raises", 10, 2);
Console.WriteLine();
Console.ReadLine();
List<Exercise> exercises = new List<Exercise>();
// create exercises
Exercise pressUps = new Exercise("Exercise 1: Press-ups kick Drills", 10, 2);
Exercise DumbbellRow = new Exercise("Exercise 2: Dumbbell row", 12, 2);
Exercise TricepDips = new Exercise("Exercise 3: Tricep dips", 12, 2);
Exercise StepUps = new Exercise("Exercise 4: Step-ups", 10, 2);
Exercise Squats = new Exercise("Exercise 5: Squats", 15, 2);
Exercise WalkingLunges = new Exercise("Exercise 6: Walking lunges", 8, 2);
Exercise SingleLegDeadLift = new Exercise("Exercise 7: Single-leg deadlift", 10, 2);
Exercise SupermanBackExtension = new Exercise("Exercise 8: Superman/back extension", 10, 2);
Exercise Glutebridge = new Exercise("Exercise 9: Glute bridge", 15, 2);
Exercise LegRaises = new Exercise("Exercise 10: Leg raises", 10, 2);
Console.WriteLine();
Console.ReadLine();
Supposedly, this is for the swimming activity, but currently, it's not specified for the swimming activity.
RTXPower
RTXPower3y ago
So you cannot do exercises.Add(pressUps) ? @Faraj
The king of kings
Well! I think I’m gonna give it another try.
RTXPower
RTXPower3y ago
Let me know what it says
The king of kings
Ok! Thanks. Well! The code that pip mentioned seems not a valid code 🤔 ‘’’swimming.Exercises = new List<Exercise>();’’’ ‘’’ swimming.Exercises.Add(//your code here); ‘’’
pip
pip3y ago
its valid, you have to add your code in the place that says your code here but ye developerplatform has it right, just add the exercises you created to the exercises list you have at the top
The king of kings
Ok! Could take a look and see if I put it in the right place. https://paste.mod.gg/dmynfesctyni/3
BlazeBin - dmynfesctyni
A tool for sharing your source code with the world!
The king of kings
This is the way I would like the project to look like, just so you can have an idea about what I'm trying to build.
pip
pip3y ago
it looks like you put it in the right place, but i don't see where Swimming is declared as an activity object now you can add the other exercises to swimming, and then you can also create your other activities and exercises for those as well
The king of kings
The errors disappeared actually This is where I'm confused, where should declare the "Swimming activity" ? Could you show me the example on how to declare an object for the Swimming activity/ program?
pip
pip3y ago
you had it here look how activity is declared
The king of kings
Ah! Ok! Got it. I will just add it then.
The king of kings
It looks good so far except for the error in the Activity class 🤷🏻‍♂️ Wow! Bingo, the error is gone now. Unfortunately, it's not outputting the exercises, and neither is the swimming activity 🤷🏻‍♂️
The king of kings
BlazeBin - ogoyajmjkqio
A tool for sharing your source code with the world!
pip
pip3y ago
first of all, there's only 1 exercise in the Swimming activity's exercises second, we haven't made the logic to output anything yet but at this point i'd recommend just playing around with your classes and figure out the best way to do it. you won't learn much if i'm writing the program for you
The king of kings
Ok! You are definitely right about that. I need to wrap around my mind and try to solve things on my own. Only simple hints would be helpful when I get really stuck. Do you mean this exercise?
exercises.Add(pressUps);
exercises.Add(pressUps);
The 1 that you mentioned?
pip
pip3y ago
yup
The king of kings
I don't really know why even we're using this code honestly 🤷🏻‍♂️ Add is a method used to add items, but in this context don't know why is it there
pip
pip3y ago
well if an activity has multiple exercises, you need to use a collection/array. in plain english it evaluates as "adding exercises to an activity"
The king of kings
Ok! Got it. You are right, it makes sense to use an array, how about "dictionaries" do you think this would do it too? Also, I wonder if I could use a for each loop-to-loop exercise for each activity?
foreach (var exercise in exercises)
{
Console.WriteLine();
}
foreach (var exercise in exercises)
{
Console.WriteLine();
}
`
pip
pip3y ago
you shouldn't worry about dictionaries yet, just uses Lists. they're easier to use than both arrays and dictionaries i'll give you a hint on foreach in this program -> find a way to fit it into the Activity class in a method blobthumbsup
The king of kings
Yeah! These are more complicated concepts, particularly for a beginner like me. Solution: override method? Correct or wrong?
pip
pip3y ago
just a method, override not necessary you have a great grasp of programming terminology, better than i did when i started. but i also get the feeling you're "reading ahead" with more advanced concepts like overriding. make sure you are practicing what you learn and really understanding it before you start jumping ahead
The king of kings
Ok! I'll try to figure this out 🙂 thanks a lot, I don't want to interrupt you with many questions 🤗 Ok
pip
pip3y ago
no problem 😄 good luck
The king of kings
Yes, thanks 😀
RTXPower
RTXPower3y ago
Overriding a method should be avoided at all cost If you have more overrides than non, you are giving every other developer a hard time
The king of kings
Ok! Well! That's interesting information to know. Someone in the C# channel recommended I would use the override method. But I'll take your advice then.
RTXPower
RTXPower3y ago
It really depends for what
The king of kings
Ok
RTXPower
RTXPower3y ago
You can override ToString but what dev will know what it will actually print? I rather make my own sort of ToString method with a decent name
The king of kings
Well! I used it here in my project and it seems that it saved me from writing some more code
public override string ToString()
{
return $"{ FullName}, { BirthDate}, { Gender}, { Language}, { Weight}, { Height}, { Address}, { EmailAddress}, { MobileNumber}";
}
public override string ToString()
{
return $"{ FullName}, { BirthDate}, { Gender}, { Language}, { Weight}, { Height}, { Address}, { EmailAddress}, { MobileNumber}";
}
var accountName = "Faraj";
Console.WriteLine($"Account is created for {accountName}");
var accountName = "Faraj";
Console.WriteLine($"Account is created for {accountName}");
Ok! Like how would you do it then?
RTXPower
RTXPower3y ago
Only thing you need to do is
public string getPersonOutput(){
return $"{ FullName}, { BirthDate}, { Gender}, { Language}, { Weight}, { Height}, { Address}, { EmailAddress}, { MobileNumber}";
}
public string getPersonOutput(){
return $"{ FullName}, { BirthDate}, { Gender}, { Language}, { Weight}, { Height}, { Address}, { EmailAddress}, { MobileNumber}";
}
But you could make that method name explain the contents a lot better I'm not sure what you are actually saving by overriding Methods like compareTo are understandable to be overridden (idk if that's a C# method but it's just an example in Java lol. Haven't had C# in a while)
The king of kings
Ah! Ok! I see. No, I'm talking about C# overriding.
RTXPower
RTXPower3y ago
It's 100% similar else I wouldn't be throwing it in here
The king of kings
Well! I didn't know that we code to use it in this way to get user inputs. Yes it is
RTXPower
RTXPower3y ago
I mean if it works and you don't need ToString for anything else then sure go ahead and use it
The king of kings
Yeah! I think I could use it whenever it's needed. I need to find a method for my project and don't know exactly which method!
The king of kings
BlazeBin - ogoyajmjkqio
A tool for sharing your source code with the world!
RTXPower
RTXPower3y ago
You mean your own method name?
The king of kings
I'm trying to use the foreach to loop all these exercises for an activity called "swimming" and then outputing.
RTXPower
RTXPower3y ago
You want to run all the exercises once? With user input considdered?
The king of kings
No, look. I will mention you. @RTXPower Yep
RTXPower
RTXPower3y ago
Oh you want to loop over the exercises that are in the list And execute the ToString for each
The king of kings
Yes
RTXPower
RTXPower3y ago
That's quite easy You can use a foreach
The king of kings
No, why do I need to use ToString?
RTXPower
RTXPower3y ago
Well you know what your ToString method does right? It returns a string you can use
The king of kings
Well! I've done it already. But it doesn't output the activity of swimming and neither the exercises that belong to swimming🤷🏻‍♂️ Yes, I've used it only in creating an account for a user. But don't need to use it when it comes to making activities and exercises in this sense.
The king of kings
In this code, I'm using only one exercise
exercises.Add(pressUps);
exercises.Add(pressUps);
RTXPower
RTXPower3y ago
Why would this output the activity?
The king of kings
I need to set all these exercises for the swimming activity and outputting them
Exercise pressUps = new Exercise("Exercise 1: Press-ups kick Drills", 10, 2);
Exercise DumbbellRow = new Exercise("Exercise 2: Dumbbell row", 12, 2);
Exercise TricepDips = new Exercise("Exercise 3: Tricep dips", 12, 2);
Exercise StepUps = new Exercise("Exercise 4: Step-ups", 10, 2);
Exercise Squats = new Exercise("Exercise 5: Squats", 15, 2);
Exercise WalkingLunges = new Exercise("Exercise 6: Walking lunges", 8, 2);
Exercise SingleLegDeadLift = new Exercise("Exercise 7: Single-leg deadlift", 10, 2);
Exercise SupermanBackExtension = new Exercise("Exercise 8: Superman/back extension", 10, 2);
Exercise Glutebridge = new Exercise("Exercise 9: Glute bridge", 15, 2);
Exercise LegRaises = new Exercise("Exercise 10: Leg raises", 10, 2);
Exercise pressUps = new Exercise("Exercise 1: Press-ups kick Drills", 10, 2);
Exercise DumbbellRow = new Exercise("Exercise 2: Dumbbell row", 12, 2);
Exercise TricepDips = new Exercise("Exercise 3: Tricep dips", 12, 2);
Exercise StepUps = new Exercise("Exercise 4: Step-ups", 10, 2);
Exercise Squats = new Exercise("Exercise 5: Squats", 15, 2);
Exercise WalkingLunges = new Exercise("Exercise 6: Walking lunges", 8, 2);
Exercise SingleLegDeadLift = new Exercise("Exercise 7: Single-leg deadlift", 10, 2);
Exercise SupermanBackExtension = new Exercise("Exercise 8: Superman/back extension", 10, 2);
Exercise Glutebridge = new Exercise("Exercise 9: Glute bridge", 15, 2);
Exercise LegRaises = new Exercise("Exercise 10: Leg raises", 10, 2);
RTXPower
RTXPower3y ago
I don't think I understand So you have a Activity Swimming = new Activity() ? If you want the exercises to belong to an activity, you should store a list of exercises within the Activity itself
The king of kings
You're right Well! How would we do that then 😄 I've been for a few weeks just trying to figure out this buddy. Let me send a copy of the project that I'm trying to build
The king of kings
This is pretty much the hierarchy of the project that I'm building 🙂 Can you open it?
RTXPower
RTXPower3y ago
List<Exercise> exercises = new List<Exercise>();

Activity swimmingAct = new Activity("Swimming");
swimmingAct.addToExercises(new Exercise("Exercise 2: Dumbbell row", 12, 2));
List<Exercise> exercises = new List<Exercise>();

Activity swimmingAct = new Activity("Swimming");
swimmingAct.addToExercises(new Exercise("Exercise 2: Dumbbell row", 12, 2));
You have to create a method like addToExercises to add to exercises list
The king of kings
Great. Looks really good. But how about if you have a 10 of them?
RTXPower
RTXPower3y ago
Well you could make addToExercises have another method signature that allows a list or array of Exercises
The king of kings
The code that you mentioned is just for 1 exercise
RTXPower
RTXPower3y ago
Yes I just said this
The king of kings
Ok!
RTXPower
RTXPower3y ago
List<Exercise> exercises = new List<Exercise>();

Activity swimmingAct = new Activity("Swimming");
swimmingAct.addToExercises(new Exercise("Exercise 2: Dumbbell row", 12, 2));

public void addToExercises(Exercise exercise)
{
exercises.Add(exercise);
}

public void addToExercises(List<Exercise> exercises)
{
exercises.AddRange(exercises);
}
List<Exercise> exercises = new List<Exercise>();

Activity swimmingAct = new Activity("Swimming");
swimmingAct.addToExercises(new Exercise("Exercise 2: Dumbbell row", 12, 2));

public void addToExercises(Exercise exercise)
{
exercises.Add(exercise);
}

public void addToExercises(List<Exercise> exercises)
{
exercises.AddRange(exercises);
}
The king of kings
I haven't worked with arrays yet, so I don't really know how to use it in this pattern actually. I have no idea what you just typed 😂
RTXPower
RTXPower3y ago
This is a list, not an array
The king of kings
But I would love to learn them anyway 😀 Yes
RTXPower
RTXPower3y ago
there is not much to it
The king of kings
I know how arrays looks like
RTXPower
RTXPower3y ago
list.Add() adds it to the list list.AddRange() adds a range of objects or whatever to that list
The king of kings
What is this void method? I see you're using it twice. Ok!
RTXPower
RTXPower3y ago
Okay so it looks like you are really new to this You might just want to follow c# docs starting from Hello World $helloworld
The king of kings
Well! I've been through the tutorials and the documents multiple times. But when it comes to applying them in various projects, I just don't know how to use them like for example what you just did in the code above. Is this the wrong way to accomplish what I'm trying?
Exercise pressUps = new Exercise("Exercise 1: Press-ups kick Drills", 10, 2);
Exercise DumbbellRow = new Exercise("Exercise 2: Dumbbell row", 12, 2);
Exercise TricepDips = new Exercise("Exercise 3: Tricep dips", 12, 2);
Exercise StepUps = new Exercise("Exercise 4: Step-ups", 10, 2);
Exercise Squats = new Exercise("Exercise 5: Squats", 15, 2);
Exercise WalkingLunges = new Exercise("Exercise 6: Walking lunges", 8, 2);
Exercise SingleLegDeadLift = new Exercise("Exercise 7: Single-leg deadlift", 10, 2);
Exercise SupermanBackExtension = new Exercise("Exercise 8: Superman/back extension", 10, 2);
Exercise Glutebridge = new Exercise("Exercise 9: Glute bridge", 15, 2);
Exercise LegRaises = new Exercise("Exercise 10: Leg raises", 10, 2);
Exercise pressUps = new Exercise("Exercise 1: Press-ups kick Drills", 10, 2);
Exercise DumbbellRow = new Exercise("Exercise 2: Dumbbell row", 12, 2);
Exercise TricepDips = new Exercise("Exercise 3: Tricep dips", 12, 2);
Exercise StepUps = new Exercise("Exercise 4: Step-ups", 10, 2);
Exercise Squats = new Exercise("Exercise 5: Squats", 15, 2);
Exercise WalkingLunges = new Exercise("Exercise 6: Walking lunges", 8, 2);
Exercise SingleLegDeadLift = new Exercise("Exercise 7: Single-leg deadlift", 10, 2);
Exercise SupermanBackExtension = new Exercise("Exercise 8: Superman/back extension", 10, 2);
Exercise Glutebridge = new Exercise("Exercise 9: Glute bridge", 15, 2);
Exercise LegRaises = new Exercise("Exercise 10: Leg raises", 10, 2);
RTXPower
RTXPower3y ago
That's just creating Exercises objects. I cannot stand by your side the whole time and teach you all this. You really need to learn use the docs If you don't know what List is and what you can do with it, go look in the docs or look at a youtube video
The king of kings
Because I see you're using a bit different concepts then mine.
BlushyFace (BlushyFace.com)
Do you understand the concepts?
The king of kings
I don't know why everyone is guiding me to use a different way to build stuff. I've watched and read the docs many times. But I'm not that advanced to be able to pick a code from the docments. Yes I do But the problem is it's very hard to choose the right code to build a project on my own.
BlushyFace (BlushyFace.com)
there are many ways to accomplish something.
The king of kings
Well! I don't know all of them and surely not the one that fits exactly what I'm trying to build. That's why many people use Stackoverflow, discord and slack just to ask and figure out the code issues If tutorials and docs would teach you everything and provides the exact code for your project, why the hell do people ask them on these different platforms that I mentioned above?
RTXPower
RTXPower3y ago
Lots of them will work and only a few of them will be very performant
The king of kings
Ok!
RTXPower
RTXPower3y ago
Don't worry about the Right way of doing things yet. Try to understand the basics. If it works, try to improve it Coding is mostly in steps
The king of kings
I'm not against you when it comes to learn and build stuff using Microsoft documents, but just like I said it's not easy for someone like me to find the exact code in the project that I'm building.
RTXPower
RTXPower3y ago
You never find the exact code in the docs. You always have to customize it to your liking Maybe you need to create a class diagram first before you start coding Just to figure out what you need
The king of kings
Ok! I've read lists many times in the doc and watched tutorials just find out how to make a list of activities like swimming, running, workout and create another list of exercises for each activity that I mentioned. Well! Docs couldn't help me with this otherwise I wouldn't spend weeks only on this step 🤷🏻‍♂️
RTXPower
RTXPower3y ago
Okay so from this, you really have 2 questions
BlushyFace (BlushyFace.com)
so what is the exact issue anyway do you understand the tutorials and are you able to apply them?
RTXPower
RTXPower3y ago
How do I create a list of exercises under an activity? How do I create a list of activities? Well to my understanding he doesn't know how to add objects into a generic list And where the lists should be initialised perhaps also
BlushyFace (BlushyFace.com)
hmm, i reckon those things are covered in beginner tutorials?
The king of kings
The problem is tutorials show what they build and they teach me through their specific project, but my project is different than theirs. So I get confused on how to apply the concepts in my project.
RTXPower
RTXPower3y ago
Maybe their project is not that different than yours?
BlushyFace (BlushyFace.com)
So the issue is that you don't know how to apply the knowledge from reading tutorials to your own project i still have no idea what the actual issue is
The king of kings
Yeah! I know. There are sometimes similarties. But still, it's hard for me.
The king of kings
Classes and objects - C# Fundamentals tutorial
Create your first C# program and explore object oriented concepts
The king of kings
Well! The way they use the "list" is almost totally different than my project. Even the foreach loop I have no idea how they use it in the properties. So things like these confuse me most of the time. Yes, this is mostly my issue when it comes to build stuff. Well! I guess we need to figure out first how to make a list of activities and then try to make a list of exercises for each activity.
BlushyFace (BlushyFace.com)
sounds fun, i know you can do it 👍
The king of kings
Thanks a lot. I guess it requires intensive paracticing and really understanding what the code you type is doing.
RTXPower
RTXPower3y ago
Ofcourse. You got the motivation. The rest will come. Just don't hurry yourself too much This is a long process for many
The king of kings
Yes, you're definitely right 🤗
The king of kings
I found this page and looks like they mentioned some of the code that you wrote https://www.tutorialsteacher.com/csharp/csharp-list
The king of kings
Could just explain to me what you use them for? Because I got multiple errors writing this code.
The king of kings
What is the purpose of using these 2 methods?
BlushyFace (BlushyFace.com)
those 2 methods with same name are overloads, however, your method does not exists for Activity. im also not sure if you are writing those 2 methods inside your main, i don't see the rest of your class.
pip
pip3y ago
public access modifiers not allowed in program.cs, just remove "public". also move it to the bottom of the file
RTXPower
RTXPower3y ago
Those 2 methods and the list belong in the Activity class as you want to add exercises to an Activity An Activity contains one or multiple exercises so that's why the Activity class should have a List of exercises and methods that allow you to add to that list.
The king of kings
Thanks, guys for all the exaplination regarding these two methods. I will modify the code and move the methods to the right place 👍 🙂
RTXPower
RTXPower3y ago
No problem. Let me know if you are stuck again
The king of kings
I will certainly do 🤗
The king of kings
BlazeBin - sittukaarodd
A tool for sharing your source code with the world!
pip
pip3y ago
that code is totally invalid you kind of got the point though
The king of kings
Oh! Really 🫣
pip
pip3y ago
public class Activity
{
public string Name { get; set; }
//public int ExerciseDuration { get; set; }
public List<Exercise> Exercises = new List<Exercise>();
public void addToExercises(Exercise exercise)
{
Exercises.Add(exercise);
}

public void addToExercises(List<Exercise> exercises)
{
Exercises.AddRange(exercises);
}

public Activity(string newName/*,int exerciseduration*/)
{
Name = newName;
//ExerciseDuration = exerciseduration;

}



}
public class Activity
{
public string Name { get; set; }
//public int ExerciseDuration { get; set; }
public List<Exercise> Exercises = new List<Exercise>();
public void addToExercises(Exercise exercise)
{
Exercises.Add(exercise);
}

public void addToExercises(List<Exercise> exercises)
{
Exercises.AddRange(exercises);
}

public Activity(string newName/*,int exerciseduration*/)
{
Name = newName;
//ExerciseDuration = exerciseduration;

}



}
The king of kings
Let me modify the code then and see if I'm it's going to print out the swimming activity + the exercises
The king of kings
It's still n ot outputing the activity neither the exercises 🤷🏻‍♂️
pip
pip3y ago
did you write the logic to ouput anything yet?
The king of kings
Not really
The king of kings
I wonder if I would use this code in my Program.cs file
Activity swimmingAct = new Activity("Swimming");
swimmingAct.addToExercises(new Exercise("Exercise 1: Press-ups kick Drills", 10, 2));
Activity swimmingAct = new Activity("Swimming");
swimmingAct.addToExercises(new Exercise("Exercise 1: Press-ups kick Drills", 10, 2));
pip
pip3y ago
yes that works I'll give you a hint, but I won't write the code for you: outputting all of the exercises in an activity can be automatic. you shouldn't have to hardcode Console.WriteLine("this exercise has 10 reps of 2 sets"); for each exercise you can write logic once and never have to worry about it again. back to what i was saying a while ago about programmers just being lazy and finding efficient solutions
The king of kings
Yeah! I do remember, but I need to go back and review again what you wrote last week. I see that you mentioned that I wrote the logic 10 times and actually the goal is to use only 1 logic that can output all at the same time 🤔
pip
pip3y ago
this is hand-in-hand with object orientation. watch a few beginner object oriented programming video examples in C#
The king of kings
Well! I think you mean that I need to use the for each loop in this case.
pip
pip3y ago
foreach is probably going to be used somewhere, that's right
The king of kings
Ok! Yeah! Actually I've seen multiple times how they accomplish this step in OOP tutorials.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
pip
pip3y ago
we're getting there pepecoffee
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The king of kings
I don't know man. Do you think the solution would be in this OOP tutorial? https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/classes@pip
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
pip
pip3y ago
there isn't a 1:1 solution, but you should be able to see how to do it in that webpage and build your own solution you can also watch videos on youtube for walkthroughs, the official c# documentation can be tough to read
The king of kings
Ok! I have a question for you then! I need to understand the code above in order to write the logic.
The king of kings
I would like to call you but you might me be busy or working now
pip
pip3y ago
i'll be off work in 2 hours if you're still up
The king of kings
Ah! Ok! How about tomorrow? I live here in Sweden and now it's 21:38 pm What is your time zone?
pip
pip3y ago
i work 6am - 2pm PST, it's 12:38 right now 😄
The king of kings
Do you live in the US? Oh! Wow 😆
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
The king of kings
Huge different in time zones 😃 Tjena tjena
pip
pip3y ago
so we can do a call before i sleep at 6am your time, or we can do a call at 23:00 your time 😄 or wait until Saturday
The king of kings
Ok! Yeah! At 23:00 that will be good. I start working at 08:30 am so no problem if I stay late, it's worth it 😁 At least I will learn some OOP concepts 😉 Are you a Swedish? Oh! I feel already sleepy, I don't think this time works well for me. How about early in the morning at 6 am in my time?
pip
pip3y ago
i start work then, don't think I can 😄
The king of kings
Ok! What time is it now in where you live?
pip
pip3y ago
its 13:30, i have 30 more minutes if you stay up 30 mins i can help
The king of kings
Aha! Ok! It's 22:31 right now here. Ok! I'll wait then. It can be a short call then. Maybe on Sunday we can go a bit deep down in more details 🙂 Awesome
pip
pip3y ago
i'm in dev-vc-0
The king of kings
Ok Hey, can I call you tomorow anytime you're available? Things looks confused for me again 🤷🏻‍♂️
pip
pip3y ago
what's the problem?
The king of kings
Well! Last time when I called and explain many things to me regarding OOP, I had to make a screen recording and I've been rewatching the video ever again. From what I see the pattren of the your project differ from the one that I have currently, I think I'm gonna create a new project and build it long side watching your video and listning to your explanation. https://paste.mod.gg/sittukaarodd/2
BlazeBin - sittukaarodd
A tool for sharing your source code with the world!
The king of kings
In the video there are many things you didn't include compare to ones I have. Like for example these codes.
Exercises.AddRange(exercises);
Exercises.AddRange(exercises);
You're adding new but mine doesn't contain one
public List<Exercise> Exercises = new List<Exercise>();
public void addToExercises(Exercise exercise)
public List<Exercise> Exercises = new List<Exercise>();
public void addToExercises(Exercise exercise)
You're not using the sets & reps
public string Name { get; set; }
public int Sets { get; set; }
public int Reps { get; set; }
public string Name { get; set; }
public int Sets { get; set; }
public int Reps { get; set; }
I don't wanna to confuse you with to much details, but I'm just cerious about some stuff and why they're there in my project 🤗
RTXPower
RTXPower3y ago
Do you not understand the code that's been given?
pip
pip3y ago
As I've said, I'm not going to explain specifically how to organize your classes. I gave you a 30 minute lecture about how objects/classes work and how they are used. You should be able to learn from this information and then apply it to your problem. A lot of the things I went over can be extended to organize the classes and their properties for your problem. If you are still confused, I recommend you continue studying and learning about classes + objects and you can use the screen capture of my presentation for guidance as well
The king of kings
Well! Not really. I don't understand the code until someone explains to me what is this code. And what is it doing? That's why I get confused. You're right. I understand your point. I need to review the lecture multiple times and make sure I understand what you're doing and how you're doing it. I don't learn that much just by giving the code for every project, then it feels like you're building stuff and not me who is practicing. I really appreciate all your explanation 🙏 🙂
The king of kings
Do you know how to solv ethis ?
Kouhai
Kouhai3y ago
You need to specify in your csproj to use C# 9.0, because the feature target-type object creation isn't avalaible in C# 8.0 target-type object creation is essentially omitting the constructors type if it's known at compile time
pip
pip3y ago
or replace new() with new List<Exercises>() you have to do what Kouhai said above in your csproj file
The king of kings
Ok! I get that, but how do I specify C#9.0, then?
pip
pip3y ago
in your csproj file, set the target to 9.0 instead of 8.0 if that gives you a new error, you have to download the new c# version
RTXPower
RTXPower3y ago
You can search up the method name in order to see how it works AddRange has two words. Add and range It will add a range of whatever you pass. As long as it's been given one of the allowed types, it should work It's basically a faster way for doing list.add() a lot of times
The king of kings
I searched many times on google but couldn't find a way to update to the C#9.0 version. I might need to download it. Ok! Thanks for all the information. I'm not sure how to apply the addRange method to my project.
BlushyFace (BlushyFace.com)
look for examples how to use addrange(...)
The king of kings
Ok! I'll definitely do that.
The king of kings
Guys, I found this content on MC website, but don't know how to excute the operation. I just wanna which C# version am I using and how to to update it to the latest version? https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#edit-the-project-file
C# language versioning - C# Guide
Learn about how the C# language version is determined based on your project and the reasons behind that choice. Learn how to override the default manually.
The king of kings
Am I using the 10th version as it's shown in the compiler?
The king of kings
OMG! I finally did it I built the project from the beginning alongside using the screen recordings from the previous lecture. I invested too much concentration in watching you explain the project building step-by-step very carefully and I understood every concept you are using. Here is the complete project for review https://paste.mod.gg/gvddmubkcfjh/2
BlazeBin - gvddmubkcfjh
A tool for sharing your source code with the world!
pip
pip3y ago
Looks good Good job i knew you could do it Now u just need to write logic so that the user selects their activity from a list, then based on their selection returns the info they want. But you got the hardest concepts down
The king of kings
Thanks a lot 🤗 it's incredable feeling everytime I feel like making progress. You're right. This is the next step that I need to figure out the functionality/ method that will enable the user to select the activity, so the activity followed by the exercises will be displayed. This one kind hard. I think I need to find a method that can enable me to select maybe one of the activity object like activity1/ activity2 etc... Because if I refernce/ choose the class Activity, then in this case we are refering to all the activities + exercises and not particularly on one activity and it's exercises, makes sense right? I think "if condition" is kind of close approach to this step. Where we could say for example; if the user select the activity1 then prompt the user with activity1 and the followed exercises. What do you think?
Kouhai
Kouhai3y ago
Yes an if statement would help you branch out.
The king of kings
Ok! Thanks a lot for your replay 🤗 you showed up in the right time 😄 I think I will need to use else if too, right?
Kouhai
Kouhai3y ago
Yup, that's absolutely right, else if would check for a condition if the previous if/else if wasn't met Later on you could take a look at "switch statement"
The king of kings
Ok! Ah! Am I gonna include switch statement too? I think the switch statement is the right option, but in this tutorial, numbers are used as case 1, case 2 and etc...
The king of kings
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
The king of kings
But in my project I'm using activities like running swimming and etc...
Kouhai
Kouhai3y ago
A switch statement would allow you branch based on "cases" so
string myString = "hello"
switch(myString)
{
case "hello":
Console.WriteLine("myString is hello!");
break;
case default:
Console.Writeline("myString isn't hello.");
break;
}
string myString = "hello"
switch(myString)
{
case "hello":
Console.WriteLine("myString is hello!");
break;
case default:
Console.Writeline("myString isn't hello.");
break;
}
this would print out myString is hello!, because myString is "hello" Also, just a small advice, avoid w3school, microsoft's docs are better 😅
The king of kings
Ok! I see your point. I'll take your advice 😉
The king of kings
Come on girl, any hint would be very appreciated 😁
The king of kings
Th problem is as you see in the screen shot. Running, Swimming are set values for objects like activity1, and activity2 so how do I add them in switch statements? The user should be able to select Running or Swimming but not activity1 or activity2 you know what I mean?
Kouhai
Kouhai3y ago
Alright First, to match a case you need to first switch
switch(variable)
{
case "one":
break;
case "two":
break;
default: // default is executed ONLY if no previous cases were met
break;
}
switch(variable)
{
case "one":
break;
case "two":
break;
default: // default is executed ONLY if no previous cases were met
break;
}
Second you can't reference a variable before it's declared
The king of kings
Ok! I understand that. I know my example of switch statement looks wrong that's why the error appears. Well! In my case if the user select "Running" then it should display the activity + exercises but then it should break the rest of activities, right?
Kouhai
Kouhai3y ago
That's correct, you need to break out of the switch statement
The king of kings
Ok! I will try to figure out a way to implement the switch statement then. Guys anyone online who can give me a hint? 😁
The king of kings
This one looks more advanced than the one I read. It's a good learning method to find what I'm looking for in the docs. Thanks. I did read the docs, but still hard how to implement the switch statement in my project. Can you give me any hint?
BlushyFace (BlushyFace.com)
what error message do you get when using a switch?
The king of kings
Well! It seems like every time I add either the class Activity in the switch statement, it throws an error. I finally did it 💪 https://paste.mod.gg/zwijkebmohqk/2 I hope the logic that wrote it's the correct way. The AddRange method is used a bit different than the way you used it 🤔
RTXPower
RTXPower3y ago
It cannot be
The king of kings
public string Name { get; set; }
//public int ExerciseDuration { get; set; }
public List<Exercise> Exercises = new List<Exercise>();
public void addToExercises(Exercise exercise)
{
Exercises.Add(exercise);
}

public void addToExercises(List<Exercise> exercises)
{
Exercises.AddRange(exercises);
}

public Activity(string newName/*,int exerciseduration*/)
{
Name = newName;
//ExerciseDuration = exerciseduration;

}
public string Name { get; set; }
//public int ExerciseDuration { get; set; }
public List<Exercise> Exercises = new List<Exercise>();
public void addToExercises(Exercise exercise)
{
Exercises.Add(exercise);
}

public void addToExercises(List<Exercise> exercises)
{
Exercises.AddRange(exercises);
}

public Activity(string newName/*,int exerciseduration*/)
{
Name = newName;
//ExerciseDuration = exerciseduration;

}
using System;
using System.Collections.Generic;

public class Example
{
public static void Main()
{
string[] input = { "Brachiosaurus",
"Amargasaurus",
"Mamenchisaurus" };

List<string> dinosaurs = new List<string>(input);

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);

Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}

Console.WriteLine("\nAddRange(dinosaurs)");
dinosaurs.AddRange(dinosaurs);

Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}
using System;
using System.Collections.Generic;

public class Example
{
public static void Main()
{
string[] input = { "Brachiosaurus",
"Amargasaurus",
"Mamenchisaurus" };

List<string> dinosaurs = new List<string>(input);

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);

Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}

Console.WriteLine("\nAddRange(dinosaurs)");
dinosaurs.AddRange(dinosaurs);

Console.WriteLine();
foreach( string dinosaur in dinosaurs )
{
Console.WriteLine(dinosaur);
}
No, I mean in comperation between those two codes.
The king of kings
List.AddRange(IEnumerable) Method (System.Collections.Generic)
Adds the elements of the specified collection to the end of the List.
The king of kings
Just trying to learn how the method is used in outputing activities like running, swimming and etc... and the exercises that are belong to each activity.
Kouhai
Kouhai3y ago
What's different between these two examples?
The king of kings
If we talk about differences from what I see they're very different from each other as a project. But what I meant is the method AddRange and how it's used in those two examples.
Kouhai
Kouhai3y ago
Yes, how are they used differently?
The king of kings
Well! It seems to me in the first example that it's basically used to add a range of exercises I guess. But I have no idea what role it plays in the second example 🤷🏻‍♂️
Kouhai
Kouhai3y ago
AddRange basically adds any IEnumrable<T> to a List<T> What that means is if you have an array of strings and want to add all these strings to another list, you would normally iterate over the array and call Add passing to it the elements. Instead of that, you can just call AddRange and pass the array to it
The king of kings
Ok! This is exactly what I discovered through searching on google. It's a method used with
Lists
Lists
&
Arrays
Arrays
But I don't understand how it's used in those examples and why?
Kouhai
Kouhai3y ago
In the second example dinosaurs is initialized with input, meaning it'll have the content's of input immediately after initialization. Then we call AddRange on dinosaurs passing to it itself, note that AddRange takes IEnumerable<T> not T[] so AddRange can take a List as well. Now the element's count in dinosaurs would be 6. In the first example it works in a similar way, you pass a List to addToExercise, that List content get's added to the Exercises property In the second example AddRange is just used as demonstration In the first example it's used to actually add those exercises to the List Exercises
The king of kings
What do you mean by element's count in dinosaurs and why would the count be 6? 🙂
Kouhai
Kouhai3y ago
dinosaurs is the list, when it's initialized, it'll have 3 elements. After calling dinosaurs.AddRange(dinosaurs) we add the list to itself, meaning the element's count is 3 + 3 = 6
The king of kings
Ok! But in the first example, the purpose of the project is to make exrecises for an activity like running, so what AddRange is doing for the project?
Kouhai
Kouhai3y ago
Activity here is a class that has a property Exercises right?
The king of kings
Ok! I kind of understand you now. Although, it's to me using this method AddRange is a bit complicated, I think. You're right 👍 🙂 Which is a list in that order.
public List<Exercise> Exercises = new List<Exercise>();
public List<Exercise> Exercises = new List<Exercise>();
Kouhai
Kouhai3y ago
Great, you have a method addToExercises(Exercise exercise) that adds an exercise to the list, right? That means if you have multiple exercises you need to call addToExercises multiple time
The king of kings
Ah! Ok! Yeah you're right.
Kouhai
Kouhai3y ago
Now you also have addToExercises(List<Exercise> exercises) which takes a list instead of taking individual ecercies and adds them to your Activity's Exercises List. That's essentially why AddRange was used
The king of kings
Yes, supposedly. Ah! Ok! Finally, I got the point about what is really going on in this code example. You're awesome at explaining things 😃
Kouhai
Kouhai3y ago
Thanks catlaugh
The king of kings
Well! This pattern seems a bit complicated to me actually. But maybe we are being lazy and using less code in this project, otherwise, we might use a lot of code in a different way. And this is just the beginning, then we need to write the logic in the Program.cs, Right?
Kouhai
Kouhai3y ago
Sorry I'm not sure I understood what the question is 😅
The king of kings
I mean the next step would be to make activities and assign exercises to each activity and this should be done in the Program.cs Right?
Kouhai
Kouhai3y ago
Yes, your code needs to be called somehow from within the main function
The king of kings
Yes, that's right. How long have you been in coding? You seem you're really good at it 😃
Kouhai
Kouhai3y ago
I think over 4 years 😅 Also, I'm not really that good there are a lot of things I don't know 😅
The king of kings
I wish someday I'd be as good as you 🤗 😀
Kouhai
Kouhai3y ago
Ty meowheart Everyone improves and learns more with practice!
The king of kings
Oh My God. 4 years 😮 Yeah! I totally agree with you. I think coding is so fun but it's hard I don't understand coding until someone explains things to me, then it sticks in my mind 😄
Kouhai
Kouhai3y ago
Yeah, that's okay, if it helps you understand how and why something is written that way.
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server