I hope you enjoyed this assignment and were able to quickly produce the correct solution.
We are now going to go over the solution to the assignment.
The question for the assignment was create a struct called car with the fields, MMORPG color and top
speed.
Once the struct is created, implement the following methods set in jpg, set color and set top speed.
Once you have created these methods, create a car, provide it with default values, and then set the
MMORPG color and top speed and then print them out.
So let's start off with creating our car strip.
And then here we need MMORPG, which will be an eight hour color, which will be a string, and then
our top speed, which will be of I 16.
Now we want to implement a few methods.
Our first method is going to be set miles per gallon.
And remember we need to reference our self.
So set miles per gallon is going to take a parameter of an eight.
And then in here we are going to say self dot.
Miles per gallon is equal to HM LPG.
So since we are changing a value in here, we now need to make it mutable.
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
is equal to color.
And then lastly, we are going to set our top speed.
And our top speed is going to be of a sixth peak and we are going to say cell top speed is equal to
top speed.
So now that we have our methods implemented, we can go to Main and now we can create our car.
And we're going to need our car to be mutable because we are going to change the values of our MMORPG
color and top speed.
So we'll say our default values for our LPG zero, our color is going to be red and then we will say
our top speed is also zero to start as well.
And now to beautify this a little bit, we will say cargo format.
I can get rid of that.
There we go.
Cargo format.
So now it's a little easier for us to read.
So now we can say car dot set miles per gallon.
We'll say we get 15 miles to the gallon.
We will say our color is blue
and now we will say our top speed is to 50.
We go really fast in this car.
So now we are going to print it out.
We want to print out our car.
So there's one thing that we need to add in order for us to be able to print out our car.
We need to add the
drive.
Debug trait and now we're able to print out our car and the top speed.
So set top speed.
And now we see that our car is now been successfully assigned the miles per gallon of 15, the blue
color and a top speed of 250.
So I hope you were able to quickly solve this assignment.
Again, if you have any questions at any time, please ask them in the Q&A section.