-1

これは、スコアのメニューを表示するコードのチャンクです。

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);
    }
}

これらの値を使用して合計スコアを計算する方法がわかりません。助けてください。

4

1 に答える 1

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;
    }
}
于 2013-02-18T20:47:00.300 に答える