1 00:00:05,840 --> 00:00:11,030 I hope you enjoyed this assignment and were able to quickly produce the correct solution. 2 00:00:11,600 --> 00:00:16,700 We are now going to go over the solution to the assignment. 3 00:00:16,940 --> 00:00:23,570 The question for the assignment was create a struct called car with the fields, MMORPG color and top 4 00:00:23,570 --> 00:00:24,170 speed. 5 00:00:24,590 --> 00:00:31,640 Once the struct is created, implement the following methods set in jpg, set color and set top speed. 6 00:00:32,300 --> 00:00:38,120 Once you have created these methods, create a car, provide it with default values, and then set the 7 00:00:38,160 --> 00:00:41,810 MMORPG color and top speed and then print them out. 8 00:00:43,130 --> 00:00:46,400 So let's start off with creating our car strip. 9 00:00:47,210 --> 00:00:55,250 And then here we need MMORPG, which will be an eight hour color, which will be a string, and then 10 00:00:55,250 --> 00:01:00,500 our top speed, which will be of I 16. 11 00:01:02,720 --> 00:01:06,590 Now we want to implement a few methods. 12 00:01:07,460 --> 00:01:12,290 Our first method is going to be set miles per gallon. 13 00:01:12,740 --> 00:01:15,140 And remember we need to reference our self. 14 00:01:15,140 --> 00:01:22,340 So set miles per gallon is going to take a parameter of an eight. 15 00:01:25,070 --> 00:01:28,820 And then in here we are going to say self dot. 16 00:01:29,030 --> 00:01:33,090 Miles per gallon is equal to HM LPG. 17 00:01:33,110 --> 00:01:38,330 So since we are changing a value in here, we now need to make it mutable. 18 00:01:40,310 --> 00:01:51,230 So now we have set color and we are going to also do a mutable self and our color is going to be a string 19 00:01:54,720 --> 00:01:56,540 is equal to color. 20 00:01:58,490 --> 00:02:02,330 And then lastly, we are going to set our top speed. 21 00:02:07,570 --> 00:02:19,630 And our top speed is going to be of a sixth peak and we are going to say cell top speed is equal to 22 00:02:19,870 --> 00:02:20,830 top speed. 23 00:02:21,160 --> 00:02:29,890 So now that we have our methods implemented, we can go to Main and now we can create our car. 24 00:02:30,760 --> 00:02:39,550 And we're going to need our car to be mutable because we are going to change the values of our MMORPG 25 00:02:39,550 --> 00:02:41,170 color and top speed. 26 00:02:43,840 --> 00:02:54,550 So we'll say our default values for our LPG zero, our color is going to be red and then we will say 27 00:02:54,550 --> 00:02:59,590 our top speed is also zero to start as well. 28 00:03:00,700 --> 00:03:05,800 And now to beautify this a little bit, we will say cargo format. 29 00:03:05,800 --> 00:03:07,300 I can get rid of that. 30 00:03:10,000 --> 00:03:10,690 There we go. 31 00:03:10,690 --> 00:03:12,100 Cargo format. 32 00:03:12,100 --> 00:03:16,360 So now it's a little easier for us to read. 33 00:03:16,360 --> 00:03:23,230 So now we can say car dot set miles per gallon. 34 00:03:23,230 --> 00:03:26,560 We'll say we get 15 miles to the gallon. 35 00:03:27,280 --> 00:03:34,600 We will say our color is blue 36 00:03:37,150 --> 00:03:42,610 and now we will say our top speed is to 50. 37 00:03:42,760 --> 00:03:44,710 We go really fast in this car. 38 00:03:45,850 --> 00:03:48,970 So now we are going to print it out. 39 00:03:52,660 --> 00:03:54,070 We want to print out our car. 40 00:03:54,100 --> 00:03:58,780 So there's one thing that we need to add in order for us to be able to print out our car. 41 00:03:59,710 --> 00:04:01,720 We need to add the 42 00:04:05,020 --> 00:04:06,340 drive. 43 00:04:08,180 --> 00:04:19,000 Debug trait and now we're able to print out our car and the top speed. 44 00:04:19,010 --> 00:04:22,430 So set top speed. 45 00:04:25,880 --> 00:04:32,540 And now we see that our car is now been successfully assigned the miles per gallon of 15, the blue 46 00:04:32,540 --> 00:04:37,040 color and a top speed of 250. 47 00:04:37,040 --> 00:04:41,000 So I hope you were able to quickly solve this assignment. 48 00:04:41,510 --> 00:04:47,480 Again, if you have any questions at any time, please ask them in the Q&A section.