Movie Store – Part 2
Goal: Quality control the Movie
class.
Unchecked exceptions
An unchecked exception crashes the app as a result of badly written code.
You should throw an:
-
IllegalArgumentException
when the caller passes faulty arguments into a method/constructor. -
IllegalStateException
when the caller invokes a method at a bad time (object not in a valid state).
Throwing an unchecked exception forces the caller to improve their code.
Task 1 – Movie
Constructor
In the Movie
constructor, throw an IllegalArgumentException
if the:
-
name
isnull
orblank
. -
format
doesn't equalDVD
ORBlue-Ray
(ignore letter case). -
rating
is less than0
or higher than10
.
Task 2 – setName
Inside setName
, throw an IllegalArgumentException
if the caller passes a name
that is blank
or null
.
Task 3 – setFormat
Inside setFormat
, throw an IllegalArgumentException
if:
-
the caller passes a
format
that isblank
ornull
. -
the
format
doesn't equalDVD
orBlue-Ray
(ignore letter case).
Task 4 – setRating
Inside setRating
, throw an IllegalArgumentException
if the rating is less than 0 or higher than 10.
That's all!
You added checkpoints to the Movie
class
. Each checkpoint forbids the caller from misusing the methods/constructors.