03-13-2010, 12:44 PM
Greetings! Last night I working on a Jeopardy game that allows you to configure the game through editing a text file.
Reason
My science teacher uses the slide show feature from OpenOffice to create Jeopardy games for test reviews. It's very fun, but sometimes he makes a mistake and it messes the entire game up... very inconsistent. So, being OCD, I have decided to make him a consistent game where he can just make different text documents to review different lessons.... here is what the text document example looks like with example input.
---------
Here is the actual text document example that the program reads from. This is placed in the same directory as the Java program. It's quite self explanatory... the first integer stands for what category the specific line being read is declaring. The second string tells whether it is defining the category name ("cat"), a question ("q:"), or an answer ("a:"). Once it has figured out what the information in the specific line is declaring, it records it in the appropriate array. Yes, it is a very simple script... but you have to admit, it's pretty long for a text document reader >.>
Oh, and before I forget... if anyone knows where to download Javax so I can use the Javax.Swing classes, could you tell me please? ;_; ty!!!
Reason
My science teacher uses the slide show feature from OpenOffice to create Jeopardy games for test reviews. It's very fun, but sometimes he makes a mistake and it messes the entire game up... very inconsistent. So, being OCD, I have decided to make him a consistent game where he can just make different text documents to review different lessons.... here is what the text document example looks like with example input.
---------
Spoiler (Click to View)
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());
}
}
}
Here is the actual text document example that the program reads from. This is placed in the same directory as the Java program. It's quite self explanatory... the first integer stands for what category the specific line being read is declaring. The second string tells whether it is defining the category name ("cat"), a question ("q:"), or an answer ("a:"). Once it has figured out what the information in the specific line is declaring, it records it in the appropriate array. Yes, it is a very simple script... but you have to admit, it's pretty long for a text document reader >.>
Spoiler (Click to View)
Code:
1 cat Cats
1 q: Question 1 Category 1
1 a: Answer 1 Category 1
1 q: Question 2 Category 1
1 a: Answer 2 Category 1
1 q: Question 3 Category 1
1 a: Answer 3 Category 1
1 q: Question 4 Category 1
1 a: Answer 4 Category 1
1 q: Question 5 Category 1
1 a: Answer 5 Category 1
2 cat Dogs
2 q: Question 1 Category 2
2 a: Answer 1 Category 2
2 q: Question 2 Category 2
2 a: Answer 2 Category 2
2 q: Question 3 Category 2
2 a: Answer 3 Category 2
2 q: Question 4 Category 2
2 a: Answer 4 Category 2
2 q: Question 5 Category 2
2 a: Answer 5 Category 2
3 cat Turtles
3 q: Question 1 Category 3
3 a: Answer 1 Category 3
3 q: Question 2 Category 3
3 a: Answer 2 Category 3
3 q: Question 3 Category 3
3 a: Answer 3 Category 3
3 q: Question 4 Category 3
3 a: Answer 4 Category 3
3 q: Question 5 Category 3
3 a: Answer 5 Category 3
4 cat Rabbits
4 q: Question 1 Category 4
4 a: Answer 1 Category 4
4 q: Question 2 Category 4
4 a: Answer 2 Category 4
4 q: Question 3 Category 4
4 a: Answer 3 Category 4
4 q: Question 4 Category 4
4 a: Answer 4 Category 4
4 q: Question 5 Category 4
4 a: Answer 5 Category 4
5 cat Frogs
5 q: Question 1 Category 5
5 a: Answer 1 Category 5
5 q: Question 2 Category 5
5 a: Answer 2 Category 5
5 q: Question 3 Category 5
5 a: Answer 3 Category 5
5 q: Question 4 Category 5
5 a: Answer 4 Category 5
5 q: Question 5 Category 5
5 a: Answer 5 Category 5
6 cat Pigs
6 q: Question 1 Category 6
6 a: Answer 1 Category 6
6 q: Question 2 Category 6
6 a: Answer 2 Category 6
6 q: Question 3 Category 6
6 a: Answer 3 Category 6
6 q: Question 4 Category 6
6 a: Answer 4 Category 6
6 q: Question 5 Category 6
6 a: Answer 5 Category 6
Oh, and before I forget... if anyone knows where to download Javax so I can use the Javax.Swing classes, could you tell me please? ;_; ty!!!