我的程序遇到了很大麻烦。这很简单,我已经完成了最后一步。现在,我不能让forloop工作并打印出电影的名称。
insertMov创建三个电影对象。对象包含名称,语言和评级。我认为这可能是我的扫描仪的一个问题,但我不确定。谢谢!
`import java.util.Scanner;
public class MovieRecommendation{
Movie [] movarr = new Movie[3];
Scanner scanner = new Scanner(System.in);
public void insertMov() {
movarr[0] = new Movie ("Avengers", "english", 2013, "pg" );
movarr[1] = new Movie ("Ironman", "english", 2008, "pg" );
movarr[2] = new Movie ("fantastic 4", "english", 2005, "pg" );
}
public String main() {
insertMov();
System.out.println("Hey, I hear you want to watch a movie.");
System.out.println("what language do you want the movie to be in?");
String langInp = scanner.nextLine();
System.out.println("Thanks! Now, what rating would you like your movie to be?");
String ratInp = scanner.nextLine();
System.out.println("Awesome :D Here are the movies Chosen for you");
for (int i = 0; i < movarr.length; i++ ){
if ( langInp == movarr[i].getLanguage() && ratInp == movarr[i].getRating()) {
System.out.println(movarr[i].getName());
}
}
return ("Feel free to use again");
}
}`