1 00:00:04,700 --> 00:00:06,740 Alright, so this challenge has got two 2 00:00:06,740 --> 00:00:09,260 parts for the first part we're going to 3 00:00:09,260 --> 00:00:11,120 override the two string function in the 4 00:00:11,120 --> 00:00:12,980 Lindt class to return a string that 5 00:00:12,980 --> 00:00:15,980 includes all the properties of loot so 6 00:00:15,980 --> 00:00:17,419 you want to test your change by running 7 00:00:17,419 --> 00:00:19,520 the program and checking and she can get 8 00:00:19,520 --> 00:00:21,349 the details of the red potion instead of 9 00:00:21,349 --> 00:00:23,599 the loot at and a hash code our putting 10 00:00:23,599 --> 00:00:25,399 what you saw that came up automatically 11 00:00:25,399 --> 00:00:27,860 unless we overrode the function the T 12 00:00:27,860 --> 00:00:29,750 string function so for the next part of 13 00:00:29,750 --> 00:00:31,640 the challenge override the two string 14 00:00:31,640 --> 00:00:34,070 function in the weapon class to return a 15 00:00:34,070 --> 00:00:35,600 string containing the weapons name and 16 00:00:35,600 --> 00:00:37,910 damage inflicted again test the changes 17 00:00:37,910 --> 00:00:40,070 by modifying the string returned by the 18 00:00:40,070 --> 00:00:42,530 player classes to string function so 19 00:00:42,530 --> 00:00:44,390 that it just uses weapon rather than 20 00:00:44,390 --> 00:00:47,150 explicitly listing the properties all 21 00:00:47,150 --> 00:00:48,530 right so that's a challenge pause the 22 00:00:48,530 --> 00:00:50,090 video and see how you go with it 23 00:00:50,090 --> 00:00:53,690 and I'll see you when you get back 24 00:00:53,690 --> 00:00:56,210 all right so I went to the solution and 25 00:00:56,210 --> 00:00:57,590 your solution may well look different 26 00:00:57,590 --> 00:00:59,300 tomorrow the important thing here is to 27 00:00:59,300 --> 00:01:01,120 display the properties of the red potion 28 00:01:01,120 --> 00:01:03,140 so for the first part of the challenge 29 00:01:03,140 --> 00:01:06,200 I'm going to go to the luke class so 30 00:01:06,200 --> 00:01:07,880 what I've chosen to do is include all 31 00:01:07,880 --> 00:01:11,240 the properties on a single line but you 32 00:01:11,240 --> 00:01:12,410 may have formatted it differently and 33 00:01:12,410 --> 00:01:14,590 that'll be fine but let's go ahead and do that 34 00:01:14,590 --> 00:01:16,850 so within the Aleut classical type 35 00:01:16,850 --> 00:01:21,170 override fund to stream and we can just 36 00:01:21,170 --> 00:01:22,550 press Enter when they see that pop up 37 00:01:22,550 --> 00:01:23,690 and it'll write out the rest of the 38 00:01:23,690 --> 00:01:26,149 class for us and I'm going to delete the 39 00:01:26,149 --> 00:01:27,950 super to string part and just add a 40 00:01:27,950 --> 00:01:30,440 double quote there or two double quotes 41 00:01:30,440 --> 00:01:35,410 in fact the dollar name is dollar type 42 00:01:35,410 --> 00:01:42,350 and is worth its base dollar value so 43 00:01:42,350 --> 00:01:46,520 that's our loot defied so let's just run 44 00:01:46,520 --> 00:01:55,670 this again 45 00:01:55,670 --> 00:01:57,350 and we can see that output is now 46 00:01:57,350 --> 00:01:59,780 working correctly we've got red potion 47 00:01:59,780 --> 00:02:02,180 is potion and is worth seven point five 48 00:02:02,180 --> 00:02:04,490 all right so on to the second part of 49 00:02:04,490 --> 00:02:06,740 the challenge let's go ahead and take 50 00:02:06,740 --> 00:02:09,139 over to their weapon class we want to 51 00:02:09,139 --> 00:02:11,030 override the two string function as well 52 00:02:11,030 --> 00:02:13,100 for that so I'm going to return a simple 53 00:02:13,100 --> 00:02:14,810 string containing the weapon name and 54 00:02:14,810 --> 00:02:17,150 the damage it does so it's going to be 55 00:02:17,150 --> 00:02:20,150 override fun to string 56 00:02:20,150 --> 00:02:23,570 enter again delete the super duck tree 57 00:02:23,570 --> 00:02:25,069 string part there and just add double 58 00:02:25,069 --> 00:02:26,840 quotes and then within the double quotes 59 00:02:26,840 --> 00:02:30,430 I'm going to put dollar name in flix 60 00:02:30,430 --> 00:02:34,730 space damage inflicted space points of 61 00:02:34,730 --> 00:02:38,090 damage all right next we're gonna go to 62 00:02:38,090 --> 00:02:40,730 the plays to string function at the 63 00:02:40,730 --> 00:02:42,140 moment you can see it's printing damage 64 00:02:42,140 --> 00:02:45,050 weapon damage inflicted what we want to 65 00:02:45,050 --> 00:02:46,670 do is firstly commit our damage 66 00:02:46,670 --> 00:02:48,050 inflicted because that's their going to 67 00:02:48,050 --> 00:02:49,489 be output by the weapons to stream 68 00:02:49,489 --> 00:02:51,620 function we want to change this line as 69 00:02:51,620 --> 00:02:54,170 well so I just says dollar weapon we're 70 00:02:54,170 --> 00:02:55,940 not going to explicitly set it to print 71 00:02:55,940 --> 00:02:58,610 out the name property that's just dollar 72 00:02:58,610 --> 00:03:01,040 weapon now and again whenever we provide 73 00:03:01,040 --> 00:03:03,140 a weapon object when Kotlin expects a 74 00:03:03,140 --> 00:03:04,970 string cotton cause the two string 75 00:03:04,970 --> 00:03:07,160 function for us so we don't need to 76 00:03:07,160 --> 00:03:08,600 include all the weapon properties we 77 00:03:08,600 --> 00:03:10,220 just included on a weapon in the string 78 00:03:10,220 --> 00:03:13,489 and it's two string function it's going 79 00:03:13,489 --> 00:03:15,019 to be used and provide the weapons 80 00:03:15,019 --> 00:03:24,390 details so let's try running the program again 81 00:03:24,390 --> 00:03:28,950 we'll just go back to a weapon class and 82 00:03:28,950 --> 00:03:31,660 the problem was I really should have 83 00:03:31,660 --> 00:03:32,650 covered to that out because that's 84 00:03:32,650 --> 00:03:34,570 really confused things it's going to be 85 00:03:34,570 --> 00:03:35,860 far better for me to actually just 86 00:03:35,860 --> 00:03:38,760 delete that line I think let's do that 87 00:03:38,760 --> 00:03:41,890 so we've just got damage which sorry 88 00:03:41,890 --> 00:03:43,240 we've just got $1 weapon printing out 89 00:03:43,240 --> 00:03:44,410 there so I'm not going to get this weird 90 00:03:44,410 --> 00:03:46,840 bit of output there so we'll run this 91 00:03:46,840 --> 00:03:56,170 again okay so that's better so you can 92 00:03:56,170 --> 00:03:57,880 see now that so that's also working 93 00:03:57,880 --> 00:04:00,370 we've got our weapon spear inflicts 14 94 00:04:00,370 --> 00:04:02,400 points of damage as you can see there so 95 00:04:02,400 --> 00:04:04,750 your code again might be different but 96 00:04:04,750 --> 00:04:06,130 if you get all the details in your 97 00:04:06,130 --> 00:04:07,690 output then well done you've completed 98 00:04:07,690 --> 00:04:09,940 the challenge alright so in the next 99 00:04:09,940 --> 00:04:11,230 video we're going to change the players 100 00:04:11,230 --> 00:04:13,660 show inventory function to deal with 101 00:04:13,660 --> 00:04:15,760 more than one bit of loot you know to do 102 00:04:15,760 --> 00:04:16,959 that we're going to have to look at how 103 00:04:16,959 --> 00:04:18,730 to get Kotlin to repeat a section of 104 00:04:18,730 --> 00:04:21,910 code multiple times using a for loop so 105 00:04:21,910 --> 00:04:24,930 I'll see you in the next video.