The goal of this workbook is the quality control, the car and dealership classes.
Because if you're on the out the way it is.
Both cars have negative price values and blank values, and these values don't make any sense and the
color should be forbidden from passing them.
So in the car constructor going to throw an illegal argument exception if the price is less than zero.
Throw a new illegal argument, exception.
Price cannot be less than zero.
We're going to throw another exception if the make is no blank, if you make is equal to no or if the
make is blank.
Throw new.
A legal argument, exception.
Make cannot be null or blank.
And if you rerun the code.
The first checkpoint crashes the app, the price cannot be less than zero, so we need to pass a valid
price values into the constructor.
And the second checkpoint crashes, the app make cannot be null or blank.
Pass valid, make values into the constructor, I'm going to put Nissan and Toyota.
And by this point, the caller has been forced to pass incorrect values into the constructor.
And so if you rerun the code, the second car's value still doesn't make any sense.
The center is another place where quality control needs to take place.
So inside set make I'm going to throw another illegal argument, exception, if the caller passes and
make that is blank or null.
There are new.
A legal argument, exception.
Make cannot be null or blank.
Rerun the code and now the checkpoint and set may crash the app, it forces the color you to pass a
valid make value to the set, make setar the stooges that.
OK, good, but clearly the price setter is another place that needs quality control.
So inside set price, I'm going to say if price is less than zero.
Then I'll throw a new illegal argument exception.
Price cannot be less than zero.
Rerun the code.
And now the checkpoint and set price crashes.
The app, it forces the caller to pass a valid price value to the set price setter.
I run the code again.
And beautiful.
Now we need to investigate the dealership class, so inside the class, there is no need to throw a
legal argument, exceptions anywhere.
Worst thing that could happen is someone could pass on a knowledge of the instructor, but the app would
already throw a null pointer exception.
The same can be said for said car.
But what if the caller passes an invalid index here?
Well, the code would already throw an array index out of bounds exception, so you throwing another
unchecked exception wouldn't make any sense.
What about an illegal state exception?
Well, let me ask you this, does that make sense for a dealership to call the sale method if there
are no cars inside?
Absolutely not.
So if the dealership is empty, then it's not in a valid state to call the sale method.
So what I'm going to do is create a separate method called exempting.
And it's going to loop through the array.
And if any of the objects is not known.
Then you're going to return false and break the loop.
Otherwise, if they all end up being null, then the dealership is empty and will return true.
And now back here, I can say if this if the current object that's calling this method is empty.
Then throw an illegal state exception.
Canacol sell when dealership is empty.
And that's all you had to checkpoints to the car dealership classes, and now each checkpoint forces
the caller to invoke the methods and constructors properly.