0

Java でクイズ ゲームをコーディングしていますが、ユーザーが行う推測の平均数を見つける方法がわかりません。簡単なコードでのゲームは次のとおりです。

import java.util.Scanner;
import java.io.File;

public class JavaQuiz 
{
    public static void main(String[] args) throws Exception
    {

        Scanner input = new Scanner(System.in);

        File file = new File("questions.txt");

        Scanner scan = new Scanner(file);
        String line;
        double lineNum = 0;
        int skip = 0;
        int correct = 0;
        double guesses = 0;

        while(scan.hasNextLine()){
            // Counting of the line number
            lineNum = lineNum + 1;
            // Scanning the next line
            line = scan.nextLine();

            // Declaring the delimeter.
            String delimiter = "\\|";
            // Splitting the line
            String[] temp = line.split(delimiter);

            // Print out the questions
            System.out.println(temp[0]);

            // Wait for the user to input
            String keyboard = input.next();
            // Take the space off the answer
            String two = temp[1].replaceAll("\\s","");

            if(keyboard.equals("q")){
                skip = skip + 1;
            }

            else{

                while(!(keyboard.equals(two)) && !(keyboard.equals("q"))){


                    keyboard = input.nextLine();

                    if(keyboard.equals("q")){
                        skip = skip + 1;
                    } else {
                        System.out.println("Incorrect. Please Try Again");
                    }

                } 

                    if(keyboard.equals(two)){
                        correct = correct + 1;
                    }
            }

        }

        System.out.println("You got " + correct + " Questions Correct.");
        System.out.println("You skipped " + skip + " questions.");
        System.out.println("And for the questions you completed, you averaged " + avg + " guesses.");        
    }
}

私はこのようなことをすべきですか?

double avg = guesses / lineNum;

何があっても0の答えが返ってきます。

4

1 に答える 1