import java.awt.*;
import java.io.*;
import hsa.Console;
public class Test4
{
static Console c;
public static void main (String [] args) throws IOException
{
c = new Console ();
int winnings = 0, number;
number = stage ("questions1.dat");
winnings += number;
c.println ("You just earned " + number);
c.println ("Your current winngins are " + winnings);
}
public static int stage (String filename) throws IOException
{
BufferedReader input;
input = new BufferedReader (new FileReader (filename));
//change the size up by one, by each question you add.
int money = 0, stg1, num = 0, size = 3;
String temp;
String [] number, question, choiceA, choiceB, choiceC, choiceD, correct;
number = new String [size];
question = new String [size];
choiceA = new String [size];
choiceB = new String [size];
choiceC = new String [size];
choiceD = new String [size];
correct = new String [size];
String answer, reply;
number [num] = input.readLine ();
while (number [num] != null)
{
question [num] = input.readLine ();
choiceA [num] = input.readLine ();
choiceB [num] = input.readLine ();
choiceC [num] = input.readLine ();
choiceD [num] = input.readLine ();
correct [num] = input.readLine ();
num++;
number [num] = input.readLine ();
}
input.close ();
boolean done = false;
stg1 = (int) (Math.random () * 2) + 1;
temp = correct [stg1 - 1].toLowerCase ();
c.println (question [stg1 - 1]);
c.print (choiceA [stg1 - 1], 30);
c.println (choiceB [stg1 - 1]);
c.print (choiceC [stg1 - 1], 30);
c.println (choiceD [stg1 - 1]);
do
{
c.print ("enter letter of correct answer: ");
answer = c.readString ();
c.println ("Is that the final answer??");
c.println ("y/n");
reply = c.readString ();
if (reply.equals ("y") || reply.equals ("Y"))
{
done = true;
}
else if (reply.equals ("n") || reply.equals ("N"))
{
c.println ("try again");
done = false;
}
else
{
c.println ("Please enter only 'y' or 'n'");
done = false;
}
}
while (!done);
if (answer.equals (correct [stg1 - 1]) || answer.equals (temp))
{
money = 100;
c.println ("you have won $100");
}
else
{
c.println ("You are history...");
}
return money;
} //stage1 method
} //test 4 class
|