This question already has an answer here:
I have an array of a class type which stores videos (not real ones just objects). Each video has a title and an author. The videos have their data set using set methods like these:
public class Clip {
private String title;
private String author;
public void setTitle (String s1) {
title = s1;
}
public void setAuthor (String s2) {
title = s2;
}
I then have a different class which creates the array and uses these set methods to enter data. The program then asks the user to select an element from the array, for example the user selects element [3]. Now the program must print the title and author of that element(video).
This is the part I am not sure how to do? Can I please have some help?
Override toString() method in Clip class as follows,
and invocation code invoke following statement,
Your implementation of Clip class is wrong. It should be something like this:
And you can retrieve your objects from array like this:
Override toString() method of Clip class. For example,
Then print the array of clips as follows:
Override toString() then simply call
If you need help creating the toString method eclipse can show you how it's done.
Press Alt+Shift+S then S , or right click -> Source -> generate toString()
Please override toString () of Clip class as below