-2
私はJavaを使い慣れていないので、クラスプロジェクトとしてJavaクイズゲームを作成しています。私の問題は、プログラムのゲームの部分にあります。私は、forループを使ってテキストファイルから各質問の質問、回答、正解、およびポイント値を読み込もうとしています。私の問題は、質問と回答を表示し、質問の正しい回答とポイント値の値を保存するために、forループ内にコードを書く方法を知らないことです。ここでフォーマットはテキストファイルにあります:Javaのテキストファイルからデータを読み込む
Question
A) answer
B) answer
C) answer
D) answer
correct answer
point value
ここに私のコードは次のとおりです。Javaでファイルの読み取り
//importing dialog box tools, scanner tools, and file reading/writing tools
import javax.swing.JOptionPane;
import java.io.*;
import java.util.Scanner;
public class JavaQuiz
{
public static void main(String[],args) throws IOException
{
//Declaring and initializing variables
String userChoice, gameQuestion, gameAnswer;
int gameScore = 0, menuChoice = 0;
//Declaring file object
File infile = new File("Questions.txt");
//Declaring scanner object for file reading
Scanner fileInput = new Scanner(infile);
//Opening statement
JOptionPane.showMessageDialog(null, "Let's Begin!");
JOptionPane.showMessageDialog(null, "First Question!");
//Reading data from "Questions.txt"
for(int i=1; i<=7; i++) //there are 7 questions in the text file.
{
}
//Closing file
fileInput.close();
}
}
JOptionPanesからすべてのテキストを表示する予定ですか? –
さて、すべてのテキストをダイアログで表示するのはひどい考えです。アプリケーションウィンドウを作成し、必要に応じて操作します。 – ifly6
私はその言語を使い慣れていないので、クラス内でアプリケーションウィンドウの使用を開始するまでには至りませんでした。私が出力を表示する方法を知っている唯一の方法は、ターミナルまたはダイアログボックスを使うことです。 – Messja93