Hey I m trying to take a String input from the user (in this case a name of a film e.g. Good Burger). I have an arraylist of class Film from which I m iterating through. On each iteration a method in the instance of class Film is called which returns a String of the film name. When I m comparing these two, it doesn t seem to recognise that they are equal and I can t figure out why.
此处为参考和比较这两种意见的代码:
用户对电影的投入。
int numberOfFilmsCheck;
numberOfFilmsCheck = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Film tempFilm;
System.out.println("Please enter the names of the films you wish to be in the new schedule");
System.out.println("Press enter after each one.");
while(numberOfFilmsCheck < numberOfFilms){
boolean foundFilm;
foundFilm = false;
String inputFilmName = null;
tempFilm = null;
String filmName;
filmName = null;
try{
inputFilmName = reader.readLine();
System.out.println(inputFilmName);
}
catch (IOException e){
System.out.println("Error");
}
for(Film film : films){
film.printFilmName();
if(inputFilmName.equals(filmName)){
foundFilm = true;
tempFilm = film;
System.out.println("Found film name");
break;
}
}
if(foundFilm == true){
newFilmsForSchedule.add(tempFilm);
numberOfFilmsCheck++;
}
else{
System.out.println("The film you entered has not been recognised.");
System.out.println("Please enter the film name as shown above.");
}
这里是班级守则。 电影:
public String getFilmName()
{
return filmName;
}
如果你注意到那里任何流ogue的印刷说明,我检查这部守则是正确的。
任何帮助都受到高度赞赏! 成就