我正在开发一个程序,但遇到了运行时问题。该程序有效,但是,在我选择电影并对其进行评分后,它应该只给出平均评分并返回开始并让用户选择另一部电影。相反,它转到默认值(else 语句)。之后,它让用户选择另一部电影。我已经尝试多次重写它,但它仍然显示这个问题,我做错了什么?我该如何解决?
import java.text.DecimalFormat;
import java.util.Scanner;
public class movie {
Scanner s1=new Scanner(System.in);
private String movielist, movie;
private double userR;
public String pg="rated PG-13", r="rated R";
public String rate="Rate this movie 1-5, 1 being terrible and 5 great";
public String crm1="Score 1 2 3 4 5\n# of Raters 1 3 1 3 12",crm2="Score 1 2 3 4 5\n# of Raters 4 2 4 6 4", crm3="Score 1 2 3 4 5\n# of Raters 3 0 5 5 7";
DecimalFormat userR1=new DecimalFormat("#.#");
public String m1(){
System.out.println("\nChoose one of the following movies\nJurassic Park, Identity Theft, The Dark Night");
movielist=s1.nextLine();
if(movielist.equalsIgnoreCase("Jurassic Park"))
{
System.out.println("Jurassic Park is "+pg+"\nCritics rated this movie: \n"+crm1+"\n"+rate);
userR=s1.nextDouble();System.out.println("With your rating, the average rating for this movie is: "+(userR1.format((82+userR)/21)));
}
else if(movielist.equalsIgnoreCase("Identity Theft"))
{
System.out.printf("Identity Theft is "+r+"\nCritics rated this movie: \n"+crm2+"\n"+rate);
userR=s1.nextDouble();
System.out.println("With your rating, the average rating for this movie is: "+(userR1.format((68+userR)/21)));
}
else if(movielist.equalsIgnoreCase("The Dark Night"))
{
System.out.printf("The Dark Night is "+pg+"\nCritics rated this movie: \n"+crm3+"\n"+rate);
userR=s1.nextDouble();
System.out.println("With your rating, the average rating for this movie is: "+(userR1.format((73+userR)/21)));
}
else
{
System.out.println("No movie with that name found, make sure your spelling is correct.");
}
return m1();
}
}