In the code below I would like to use indexOf(), but I can't find the proper way.
Movie class:
public class Movie {
private String title;
private String genre;
private String actor;
private int yearPublished;
public Movie(String title, String genre, String actor, int yearPublished) {
this.title = title;
this.genre = genre;
this.actor = actor;
this.yearPublished = yearPublished;
}
@Override
public String toString() {
return title + ", Genre: " + genre + ", Actor(s):" + actor + ", Year of publishing: " + yearPublished;
}
public String getTitle() {
return title;
}
public String getGenre() {
return genre;
}
public String getActor() {
return actor;
}
public int getYearPublished() {
return yearPublished;
}
}
Controller class:
public class Controller {
void start() {
scanning();
printing("Movies:");
selectYourMovie();
}
private List<Movie> movies = new ArrayList<>();
private void scanning() {
try {
Scanner fileScanner = new Scanner(new File("movies.txt"));
String row;
String []data;
while (fileScanner.hasNextLine()) {
row = fileScanner.nextLine();
data = row.split(";");
movies.add(new Movie(data[0], data[1], data[2], Integer.parseInt(data[3])));
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void printing(String cim) {
for (Movie movie : movies) {
System.out.println(movie);
}
}
private void selectYourMovie() {
System.out.println(movies.indexOf(/*What to put here?*/);
}
}
And the content of the txt file:
The Matrix;action;Keanu Reeves;1999
The Lord of the Rings;fantasy;Elijah Wood;2001
Harry Potter;fantasy;Daniel Radcliffe;2001
The Notebook;drama;Ryan Gosling;2004
Step Up;drama, dance;Channing Tatum;2006
Pulp Fiction;crime;Samuel L. Jackson, John Travolta;1994
Star Wars: A New Hope;action;Mark Hamill;1977
So I would like to return the index of the given movie, but I couldn't find how to do it with a list which has multiple objects. Since passing an entire line of the txt doesn't work.
Any hints on this?