I made a post earlier about a similar topic. However, I thought I would clarify something and change my question.
So this project I am doing is confusing me. I am only 5 weeks in and the question is asking me to create a method that returns a title of a photo in an array of photos. each photo has a title. This is the code:
public class Album {
private String albumtitle;
private ArrayList<Photo> photos;
/**
* This constructor should initialize the
* instance variables of the class.
*/
public Album(String title) {
this.albumtitle = title;
photos = new ArrayList<>();
}
/** When passed a title, this method should
* return the first Photo object in the album with
* a matching title. If there is no such object, it
* should return null.
*
* @param title A title to search for
* @return A Photo object, or null
*/
public Photo searchByTitle(String title) {
//TODO enter code here
}
}
Now, my lecturer said not to use for loops as the project is from chapter 1 to 4 (chapter 5 is for loops/iterations)
This is an example of what the lecturer did with a program about books without using for loops. However, notice it has (int index) as a parameter and then uses String title = bookTitles.get(index)
My point is, how do I do it without using for loop? I don't want them to feel as I have copied off the internet something we haven't learned.
Thanks,
equalsproperly too.