Alright, so this challenge has got two
parts for the first part we're going to
override the two string function in the
Lindt class to return a string that
includes all the properties of loot so
you want to test your change by running
the program and checking and she can get
the details of the red potion instead of
the loot at and a hash code our putting
what you saw that came up automatically
unless we overrode the function the T
string function so for the next part of
the challenge override the two string
function in the weapon class to return a
string containing the weapons name and
damage inflicted again test the changes
by modifying the string returned by the
player classes to string function so
that it just uses weapon rather than
explicitly listing the properties all
right so that's a challenge pause the
video and see how you go with it
and I'll see you when you get back
all right so I went to the solution and
your solution may well look different
tomorrow the important thing here is to
display the properties of the red potion
so for the first part of the challenge
I'm going to go to the luke class so
what I've chosen to do is include all
the properties on a single line but you
may have formatted it differently and
that'll be fine but let's go ahead and do that
so within the Aleut classical type
override fund to stream and we can just
press Enter when they see that pop up
and it'll write out the rest of the
class for us and I'm going to delete the
super to string part and just add a
double quote there or two double quotes
in fact the dollar name is dollar type
and is worth its base dollar value so
that's our loot defied so let's just run
this again
and we can see that output is now
working correctly we've got red potion
is potion and is worth seven point five
all right so on to the second part of
the challenge let's go ahead and take
over to their weapon class we want to
override the two string function as well
for that so I'm going to return a simple
string containing the weapon name and
the damage it does so it's going to be
override fun to string
enter again delete the super duck tree
string part there and just add double
quotes and then within the double quotes
I'm going to put dollar name in flix
space damage inflicted space points of
damage all right next we're gonna go to
the plays to string function at the
moment you can see it's printing damage
weapon damage inflicted what we want to
do is firstly commit our damage
inflicted because that's their going to
be output by the weapons to stream
function we want to change this line as
well so I just says dollar weapon we're
not going to explicitly set it to print
out the name property that's just dollar
weapon now and again whenever we provide
a weapon object when Kotlin expects a
string cotton cause the two string
function for us so we don't need to
include all the weapon properties we
just included on a weapon in the string
and it's two string function it's going
to be used and provide the weapons
details so let's try running the program again
we'll just go back to a weapon class and
the problem was I really should have
covered to that out because that's
really confused things it's going to be
far better for me to actually just
delete that line I think let's do that
so we've just got damage which sorry
we've just got $1 weapon printing out
there so I'm not going to get this weird
bit of output there so we'll run this
again okay so that's better so you can
see now that so that's also working
we've got our weapon spear inflicts 14
points of damage as you can see there so
your code again might be different but
if you get all the details in your
output then well done you've completed
the challenge alright so in the next
video we're going to change the players
show inventory function to deal with
more than one bit of loot you know to do
that we're going to have to look at how
to get Kotlin to repeat a section of
code multiple times using a for loop so
I'll see you in the next video.