这是显示分数菜单的代码块:
public void scoreBoard() //the score board to keep count; need to display 4 times
{
Scanner score = new Scanner (System.in);
for (int k = 1; k <= 4; k++) //repeat for the 4 quarters
{
System.out.println( "T : " );
System.out.println( touchdown * score.nextInt()); //scores of the plays made
System.out.println("F : ");
System.out.println(fieldgoal * score.nextInt());
System.out.println("E : ");
System.out.println ( extrapnt * score.nextInt());
System.out.println ("P : ");
System.out.println ( twopntcon * score.nextInt());
System.out.println("S : " );
System.out.println( safety * score.nextInt());
System.out.println ( "Q : Done with quarter " + k);
}
}
我似乎无法弄清楚如何使用这些值并计算总分。请帮忙。
答案 0 :(得分:1)
我假设您的问题是如何重复使用扫描仪值进行计算和打印。试试这个:
public void scoreBoard()
{
int total = 0;
Scanner score = new Scanner (System.in);
for (int k = 1; k <= 4; k++) //repeat for the 4 quarters
{
int touchdown_score = touchdown * score.nextInt();
int fieldgoal_score = fieldgoal * score.nextInt();
int extra_score = extrapnt * score.nextInt();
int twopnt_score = twopntcon * score.nextInt();
int safety_score = safety * score.nextInt();
System.out.println( "T : " );
System.out.println( touchdown_score ); //scores of the plays made
System.out.println("F : ");
System.out.println(fieldgoal_score);
System.out.println("E : ");
System.out.println (extra_score );
System.out.println ("P : ");
System.out.println (twopnt_score);
System.out.println("S : " );
System.out.println(safety_score);
System.out.println ( "Q : Done with quarter " + k);
total+= touchdown_score + fieldgoal_score + extra_score + twopnt_score + safety_score;
}
}