The constructor's the first thing that runs as soon as you create a new object.
So it should be the one to update the fields of a newly created object.
In this lesson, you're going to fix your constructor.
Right now, we're calling the Senate to update the cars field, remove it.
Because when you create a new object, it's the constructor's job to update every field.
The dealership only has one field, so the constructor needs to receive one parameter.
An array of car objects and instead of a fixed length of three, the field is going to share the same
length as the parameter that gets passed in.
All right, so back in Maine, you need to pass in one argument that wage Albino's to call the constructor
with one parameter.
And the argument we're going to pass on is the cars are Ray.
And before testing the code, I'm going to add two more cars to the array being Pastan.
It's going to be a Honda.
Worth 7000 made in 2019.
A color of orange, and it's going to come with the standard tires and filter.
The last car is going to be a Mercedes worth twelve thousand.
Made in 2015, color of black.
And it's going to come with tires, filters, and that's put in a transmission.
All right.
And feel free to add as many car objects as you'd like, but I'm going to go ahead and print the dealership
object.
All right, there are five spots in the cars field and all of them are empty.
This makes sense because so far we're only set the length of the Crisfield, we still have an updated
every element, so every element along the array is going to be no.
OK, so the next step is to update every element in the cars filled with an object from the car's parameter.
So create a fault that runs through the length of the car's perimeter.
We can use the fawry shortcut and it creates a far loop that runs through the length of the nearest
array.
And now the cars field and cars parameter share the same length.
So using this for a loop, it can index every element in the car's field.
And at this point, careful not to fall into the reference trap.
Said every element in the cars field equal to a new car object.
In each new car, object is going to copy its values from a source and this source is going to be the
object that we're indexing from the car's parameter.
And that's it, you're ready to run your code.
And that's perfect.
There are five spots in the cars field and the constructor sets every element in the cars field equal
to an object from the car's parameter.
Why not use a raise a copy of.
You should not use a raised copy of for an array of objects.
A radar copy of Shallow Copy is the reference from every element.
So elements from both arrays are going to share a reference to the same object.
In other words, this would be the same thing as writing this.
Which means would be falling into a trap to.
Instead, use a loop that deep copies the object from every element.
So be careful, a, that copy of is going to shallow copy the reference of every element.
However, the loop deep copies the object from every element.
In this lesson, you fix the dealership constructor.
At first we were using the center to update the newly created dealership object, but when you create
a new object, it's the constructors job to run and update your fields.
In this case, the constructor sets every element in the car's field equal to an object from the car's
parameter.