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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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 tutorials don't explain more deeply, they only explain very basic stuff.
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?
(i'm not quizzing you, i'm trying to explain how to think about classes + objects by guiding you through it)
Ok
So what, in your mind, is the difference in content between Exercise 1 and Exercise 2
I guess only the name of the exercises and the number of the Reps & sets
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)
Well! The conditions like the Ifs + the variables
Kindof, but not exactly. Think a bit deeper. What do all of these exercises have in common? Terminology wise
(hint, you already told me)
I guess I'm repeating the same if conditions over and over again
Reps, Sets, and Name is the same for each, right?
Every exercise will have a rep, set, and a name
Yeah
Guaranteed
Correct
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
Now how do I differentiate Situps from Pushups?
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?
OMG, you're great bro at explaining things.
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)
Well! I guess we can use the swith statements or the break I don't know.
it's even easier than that
We stop looping by using break
we aren't at loops yet, just defining exercises
so this is how you would do it
Ok
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
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
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
Although your method of creating the project would be a good practice
yes
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?
I'm thinknig
No
Can I please call you
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
Ah! Ok! It's alright.
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,
Ok! Thanks
and then you can write your logic ONCE that applies for every exercise
Boom, object orientation
Wow! Great.
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
You're absloutly right
Ok
And now that you have this context, take a look at the code that @Lurch sent you
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?
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
It's the same
Ohhh I'm more referring to like line 100+
Ok
Yes you did
ok
so each activity has exercises yes?
Yes
using the code I have above you can do something like
Ok
Because each activity has its own exercises, each exercise has its own reps/sets right?
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?
Yup you can have a list in your properties, you can have anything in your properties
yea actually you can probably just do instead to initialize it
Ok! But why do people make a list in the Program.cs
then do add stuff, you can do
And not in the properties
well it depends on what you're doing
because a list of activities isn't in the properties of an object somewhere right?
Ok
so you'll have to make that somewhere else, not in a class
Yes
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
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 🙏 🙂
no problem 😄 good luck
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
or this one
I got a bit confused
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
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.
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
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?
the only difference between activities is their name, and the exercises in the activity
let's add a constructor to make it easy
then when using this class in your program, we can do
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.
Exercises are objects, so you have to instantiate them
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?
And we compliment/ referance each other in this code
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
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
Ok
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"
Yes, that's right.
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
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?
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
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...
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.
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.
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.
That's perfectly clear to me
Great to hear that
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 😄
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 🤗
ok sounds good 👍
Thanks
This project might look simple, but it's really a paining in the ass 😂
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!
I hope I git it right, although there are many errors 🤷🏻♂️
it looks OK so far, you're probably going to have to move your exercise class outside of the activity class though
You mean, I need to create a new class called "public class Exercise"?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok! Here is the updated version. https://paste.mod.gg/nxitcauurcce/2
BlazeBin - nxitcauurcce
A tool for sharing your source code with the world!
Still need to move class Exercise out of class Activity make an Exercise.cs file and move your class code to that file and make it public
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,
What, I already did, it's in a new class file.
Look
Oh! Sorry, I forgot to edit the code in the BlazeBin.
ah ok
read that exception though, i'm certain you can find what's wrong
BlazeBin - qlcjojvtkhcm
A tool for sharing your source code with the world!
Now it's ready to be reviewed.
there is no argument found that corresponds to parameter called name
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.
Ok!It always says the same.
is there anything in your constructor?
the one that exists currently?
I do have a constructer that contains parameters 🤷🏻♂️
so with this in mind, what's missing when you're initializing your Exercise object?
Well! I guess arguments are missing. Right?
Ah! Ok! Wait minute.
yup
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.
this is what is missing, you already got it
you need to pass arguments into your constructor
Well! Not only that. I have thought about something else too.
I usually do it every time I make an object
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!
BlazeBin - vhaqpnydhizk
A tool for sharing your source code with the world!
That's strange 🤔 Still the arguments issue appears, although I had to modify the code.
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
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?
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
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.
Supposedly, this is for the swimming activity, but currently, it's not specified for the swimming activity.
So you cannot do
exercises.Add(pressUps)
?
@FarajWell! I think I’m gonna give it another try.
Let me know what it says
Ok! Thanks.
Well! The code that pip mentioned seems not a valid code 🤔
‘’’swimming.Exercises = new List<Exercise>();’’’
‘’’ swimming.Exercises.Add(//your code here); ‘’’
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
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!
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.
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 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?
you had it here
look how activity is declared
Ah! Ok! Got it. I will just add it then.
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 🤷🏻♂️
BlazeBin - ogoyajmjkqio
A tool for sharing your source code with the world!
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
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?
The 1 that you mentioned?
yup
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
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"
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? `
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
Yeah! These are more complicated concepts, particularly for a beginner like me.
Solution: override method? Correct or wrong?
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
Ok! I'll try to figure this out 🙂 thanks a lot, I don't want to interrupt you with many questions 🤗
Ok
no problem 😄 good luck
Yes, thanks 😀
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
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.
It really depends for what
Ok
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
Well! I used it here in my project and it seems that it saved me from writing some more code
Ok! Like how would you do it then?
Only thing you need to do is
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)
Ah! Ok! I see. No, I'm talking about C# overriding.
It's 100% similar
else I wouldn't be throwing it in here
Well! I didn't know that we code to use it in this way to get user inputs.
Yes it is
I mean if it works and you don't need ToString for anything else then sure go ahead and use it
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!
BlazeBin - ogoyajmjkqio
A tool for sharing your source code with the world!
You mean your own method name?
I'm trying to use the foreach to loop all these exercises for an activity called "swimming" and then outputing.
You want to run all the exercises once?
With user input considdered?
No, look. I will mention you.
@RTXPower
Yep
Oh you want to loop over the exercises that are in the list
And execute the ToString for each
Yes
That's quite easy
You can use a foreach
No, why do I need to use ToString?
Well you know what your ToString method does right?
It returns a string you can use
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.
In this code, I'm using only one exercise
Why would this output the activity?
I need to set all these exercises for the swimming activity and outputting them
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 itselfYou'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
This is pretty much the hierarchy of the project that I'm building 🙂
Can you open it?
You have to create a method like
addToExercises
to add to exercises
listGreat. Looks really good. But how about if you have a 10 of them?
Well you could make
addToExercises
have another method signature that allows a list or array of ExercisesThe code that you mentioned is just for 1 exercise
Yes
I just said this
Ok!
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 😂
This is a list, not an array
But I would love to learn them anyway 😀
Yes
there is not much to it
I know how arrays looks like
list.Add() adds it to the list
list.AddRange() adds a range of objects or whatever to that list
What is this void method? I see you're using it twice.
Ok!
Okay so it looks like you are really new to this
You might just want to follow c# docs starting from Hello World
$helloworld
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
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?
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
Because I see you're using a bit different concepts then mine.
Do you understand the concepts?
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.
there are many ways to accomplish something.
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?
Lots of them will work and only a few of them will be very performant
Ok!
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
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.
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
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 🤷🏻♂️
Okay so from this, you really have 2 questions
so what is the exact issue anyway do you understand the tutorials and are you able to apply them?
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
hmm, i reckon those things are covered in beginner tutorials?
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.
Maybe their project is not that different than yours?
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
Yeah! I know. There are sometimes similarties. But still, it's hard for me.
Look to this link they are building a bank account https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/classes
Classes and objects - C# Fundamentals tutorial
Create your first C# program and explore object oriented concepts
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.
sounds fun, i know you can do it 👍
Thanks a lot. I guess it requires intensive paracticing and really understanding what the code you type is doing.
Ofcourse.
You got the motivation. The rest will come.
Just don't hurry yourself too much
This is a long process for many
Yes, you're definitely right 🤗
I found this page and looks like they mentioned some of the code that you wrote https://www.tutorialsteacher.com/csharp/csharp-list
Could just explain to me what you use them for? Because I got multiple errors writing this code.
What is the purpose of using these 2 methods?
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.
public access modifiers not allowed in program.cs, just remove "public". also move it to the bottom of the file
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.
Thanks, guys for all the exaplination regarding these two methods. I will modify the code and move the methods to the right place 👍 🙂
No problem. Let me know if you are stuck again
I will certainly do 🤗
I hope I got it right https://paste.mod.gg/sittukaarodd/0
BlazeBin - sittukaarodd
A tool for sharing your source code with the world!
that code is totally invalid
you kind of got the point though
Oh! Really 🫣
Let me modify the code then and see if I'm it's going to print out the swimming activity + the exercises
It's still n ot outputing the activity neither the exercises 🤷🏻♂️
did you write the logic to ouput anything yet?
Not really
I wonder if I would use this code in my Program.cs file
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
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 🤔
this is hand-in-hand with object orientation. watch a few beginner object oriented programming video examples in C#
Well! I think you mean that I need to use the for each loop in this case.
foreach is probably going to be used somewhere, that's right
Ok! Yeah! Actually I've seen multiple times how they accomplish this step in OOP tutorials.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
we're getting there
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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
Ok! I have a question for you then! I need to understand the code above in order to write the logic.
I would like to call you but you might me be busy or working now
i'll be off work in 2 hours if you're still up
Ah! Ok! How about tomorrow?
I live here in Sweden and now it's 21:38 pm
What is your time zone?
i work 6am - 2pm PST, it's 12:38 right now 😄
Do you live in the US?
Oh! Wow 😆
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Huge different in time zones 😃
Tjena tjena
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
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?
i start work then, don't think I can 😄
Ok! What time is it now in where you live?
its 13:30, i have 30 more minutes
if you stay up 30 mins i can help
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
i'm in dev-vc-0
Ok
Hey, can I call you tomorow anytime you're available? Things looks confused for me again 🤷🏻♂️
what's the problem?
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!
In the video there are many things you didn't include compare to ones I have. Like for example these codes.
You're adding new but mine doesn't contain one
You're not using the sets & reps
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 🤗
Do you not understand the code that's been given?
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
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 🙏 🙂
Do you know how to solv ethis ?
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 timeor replace new() with new List<Exercises>()
you have to do what Kouhai said above in your csproj file
Ok! I get that, but how do I specify C#9.0, then?
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
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 timesI 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.
look for examples how to use addrange(...)
Ok! I'll definitely do that.
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.
Am I using the 10th version as it's shown in the compiler?
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!
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
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?
Yes an if statement would help you branch out.
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?
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"
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...
But in my project I'm using activities like running swimming and etc...
A switch statement would allow you branch based on "cases"
so
this would print out
myString is hello!
, because myString is "hello"
Also, just a small advice, avoid w3school, microsoft's docs are better 😅Ok! I see your point. I'll take your advice 😉
Come on girl, any hint would be very appreciated 😁
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?
Alright
First, to match a
case
you need to first switch
Second you can't reference a variable before it's declaredOk! 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?
That's correct, you need to break out of the switch statement
Ok! I will try to figure out a way to implement the switch statement then.
Guys anyone online who can give me a hint? 😁
when in doubt read the docs https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/selection-statements
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?
what error message do you get when using a switch?
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 🤔
It cannot be
No, I mean in comperation between those two codes.
The second code is an example from the MC docs https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.addrange?view=net-7.0
List.AddRange(IEnumerable) Method (System.Collections.Generic)
Adds the elements of the specified collection to the end of the List.
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.
What's different between these two examples?
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.
Yes, how are they used differently?
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 🤷🏻♂️
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 itOk! This is exactly what I discovered through searching on google. It's a method used with &
But I don't understand how it's used in those examples and why?
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
What do you mean by element's count in dinosaurs and why would the count be 6? 🙂
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 = 6Ok! 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?
Activity here is a class that has a property
Exercises
right?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.
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 timeAh! Ok! Yeah you're right.
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 usedYes, supposedly.
Ah! Ok! Finally, I got the point about what is really going on in this code example. You're awesome at explaining things 😃
Thanks
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?
Sorry I'm not sure I understood what the question is 😅
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?
Yes, your code needs to be called somehow from within the main function
Yes, that's right.
How long have you been in coding?
You seem you're really good at it 😃
I think over 4 years 😅
Also, I'm not really that good there are a lot of things I don't know 😅
I wish someday I'd be as good as you 🤗 😀
Ty
Everyone improves and learns more with practice!
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 😄
Yeah, that's okay, if it helps you understand how and why something is written that way.
✅ This post has been marked as answered!