Code:
import java.io.*;
public class JeopardyUploader
{
public static void main(String[] args) //puts text file info into variable
{
try
{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("GameData.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
String[] GameData; //declaring an array
String[] cats; //declaring an array
String[] cat1a; //declaring an array
String[] cat1q; //declaring an array
String[] cat2a; //declaring an array
String[] cat2q; //declaring an array
String[] cat3a; //declaring an array
String[] cat3q; //declaring an array
String[] cat4a; //declaring an array
String[] cat4q; //declaring an array
String[] cat5a; //declaring an array
String[] cat5q; //declaring an array
String[] cat6a; //declaring an array
String[] cat6q; //declaring an array
int cntCats = 0;
int cntCat1a = 0;
int cntCat1q = 0;
int cntCat2a = 0;
int cntCat2q = 0;
int cntCat3a = 0;
int cntCat3q = 0;
int cntCat4a = 0;
int cntCat4q = 0;
int cntCat5a = 0;
int cntCat5q = 0;
int cntCat6a = 0;
int cntCat6q = 0;
GameData = new String[200]; // Recorded lines in text document gamedata.txt
cats = new String[6]; // List of categories
cat1q = new String[5]; // Questions for Category 1
cat1a = new String[5]; // Answers for Category 1
cat2q = new String[5]; // Questions for Category 2
cat2a = new String[5]; // Answers for Category 2
cat3q = new String[5]; // Questions for Category 3
cat3a = new String[5]; // Answers for Category 3
cat4q = new String[5]; // Questions for Category 4
cat4a = new String[5]; // Answers for Category 4
cat5q = new String[5]; // Questions for Category 5
cat5a = new String[5]; // Answers for Category 5
cat6q = new String[5]; // Questions for Category 6
cat6a = new String[5]; // Answers for Category 6
int counter1 = 0;
for(;(strLine = br.readLine()) != null;counter1 += 1)
{
// Print the content on the console
GameData[counter1] = strLine; // initialize first element
//System.out.println("Line" + counter1 + ": " + GameData[counter1]);
}
//Close the input stream
int counter2 = 0;
for(;counter2 < counter1;counter2++)
{
String line = GameData[counter2];
boolean b = false;
int cat_num = 0;
cat_num = Integer.parseInt(line.substring(0,1));
String cat_numString = line.substring(0,1);
b = line.startsWith(cat_numString + " cat");
if(b)
{
cats[cntCats] = line.substring(5);
//System.out.println("Category: " + cats[cntCats]);
cntCats++;
}
else
{
b = line.startsWith(cat_numString + " q:");
if(b)
{
if(cat_num == 1)
{
cat1q[cntCat1q] = line.substring(5);
//System.out.println("Question: " + cat1q[cntCat1q]);
cntCat1q++;
}
else
if(cat_num == 2)
{
cat2q[cntCat2q] = line.substring(5);
//System.out.println("Question: " + cat2q[cntCat2q]);
cntCat2q++;
}
if(cat_num == 3)
{
cat3q[cntCat3q] = line.substring(5);
//System.out.println("Question: " + cat3q[cntCat3q]);
cntCat3q++;
}
else
if(cat_num == 4)
{
cat4q[cntCat4q] = line.substring(5);
//System.out.println("Question: " + cat4q[cntCat4q]);
cntCat4q++;
}
else
if(cat_num == 5)
{
cat5q[cntCat5q] = line.substring(5);
//System.out.println("Question: " + cat5q[cntCat5q]);
cntCat5q++;
}
else
if(cat_num == 6)
{
cat6q[cntCat6q] = line.substring(5);
//System.out.println("Question: " + cat6q[cntCat6q]);
cntCat6q++;
}
}
else
{
b = line.startsWith(cat_numString + " a:");
if(b)
{
if(cat_num == 1)
{
cat1q[cntCat1a] = line.substring(5);
//System.out.println("Answer: " + cat1q[cntCat1a]);
cntCat1a++;
}
else
if(cat_num == 2)
{
cat2q[cntCat2a] = line.substring(5);
//System.out.println("Answer: " + cat2q[cntCat2a]);
cntCat2a++;
}
else
if(cat_num == 3)
{
cat3q[cntCat3a] = line.substring(5);
//System.out.println("Answer: " + cat3q[cntCat3a]);
cntCat3a++;
}
else
if(cat_num == 4)
{
cat4q[cntCat4a] = line.substring(5);
//System.out.println("Answer: " + cat4q[cntCat4a]);
cntCat4a++;
}
else
if(cat_num == 5)
{
cat5q[cntCat5a] = line.substring(5);
//System.out.println("Answer: " + cat5q[cntCat5a]);
cntCat5a++;
}
else
if(cat_num == 6)
{
cat6q[cntCat6a] = line.substring(5);
//System.out.println("Answer: " + cat6q[cntCat6a]);
cntCat6a++;
}
}
}
}
}
in.close();
}
catch (Exception e)
{
//Catch exception if any
System.err.println("Error: " + e.getMessage() + " - " + e.getCause());
}
}
}