In this video, I'm going to cover part one of the vending machine application.
The first task was to add the necessary fields to the item class, and if you look back at the requirements,
the fields are private string name.
Private double price.
And private int quantity.
All right, now, remember that if a class is fields, you need to apply the big three steps.
We need to take instructor getters and setters and the constructor is going to be public.
It's going to take as many parameters as there are fields, so three.
And the constructor runs when you create a new object, so we're going to set every field in that object
equal to a parameter value.
All right, simple enough, and now we can use Intellisense to autocomplete, the getters and setters.
Now, Task three told us to add a copy constructor because at some point we're going to need a way to
copy Eitam objects without falling into the trap so we can simply copy this constructor.
And instead of parameters, we're going to be obtaining values from a source object.
And then we're just going to set every field in the current object equal to the field value from a source
object.
All right, and now task force tells us that every class that models an object should have a two string
method.
So we're going to add it to three methods, our class.
And copy over the format.
And will replace the placeholders where we need to.
This name.
Colin.
The stock price.
Put a space here where they put a bracket.
Embed the quantity inside of another Brackett's.
All right, we're done creating the item class.
So inside main.
I'm going to create a new object of the item class.
I'm going to pass in an item named Pepsi worth three ninety nine.
And there is going to be three Pepsis inside the vending machine.
All right, and we can print the object.
Run the code.
And everything works beautifully.