So I have a video inventory program,
Where the user creates a object of the class video by initializing the constructor
Video video=new Video(String name){
this.name=name
}
Now I have three more parameterized constructor
Video video=new Video(String name, int rating){
this.name=name;
this.rating=rating;
}
Video video=new Video(String name, int rating, boolean checkout){
this.name=name;
this.rating=rating;
this.checkout=checkout;
}
Video video=new Video(String name, boolean checkout){
this.name=name;
this.checkout=checkout;
}
Each video added is stored in a Video[] store
array
First the user adds the video only by passing the name (eg.Matrix) and creates the object of the video, it gets added in the Video[] store
What I want is that whenever a another parameter is added to Matrix , suppose int rating
, it first finds Matrix from the Video[] store
array, then checks whether the boolean checkout
parameter exists or not.
if boolean checkout
exists it passes the values to the constructor Video video=new Video(String name, int rating, boolean checkout)
else it passes values to the constructor Video video=new Video(String name, int rating)
.
I want to know how to check if a parameter exists or not.
Another approach I wanted to take was to set one constructor Video(String name)
and use null values to initialize the variables and later change them using setters, but you can't set int
and boolean
to null.
So I have to use it like this (as I found on the internet)
Video(String name){
this.videoName=name;
this.rating=(Integer) null;
this.checkout=(Boolean) null;
}
but this requires unboxing or something which I have no idea how to do. So any help would be appreciated. :)