In case you get stuck anywhere, don't be afraid to ask the coaches! They are here to help and will gladly explain everything to you!
Take notes during the exercises. Even if you never look at them again, they will help you memorise things!
The topic of Classes is an extensive one. Therefore we created a few exercises for you. Let’s start with an easy one. You should find all help in the slides. You saw how to create a Cat class. So let’s create a Dog class.
Here’s what it should do when it’s all finished:
Create a class named Dog
.
Initialize it with the three arguments: name
, number_of_dog_friends
, favourite_food
.
Test your code by create a new Dog
called Sniff, with number of dog friends 5
and favourite food "bacon"
.
Now we want to enable some behaviour and actions. That means we need to write some methods. Let’s first write a method bark
. After calling this method the dog should bark. Call the method on Sniff and let him bark to test it.
We want to give the dog a toy. Make a method give_a_toy
and store the toys in an array. Give Sniff three different toys.
Create a method information
which will output following string: ‘The dog Sniff has 5 dog friends and 3 toys. His favourite food is bacon.’
Congrats, you made it! ;o)