This is my program
///////////////////////////////////////////////////////////////////////////////////
// ICS 3U1 - Mrs. Shanks
// Asad Choudhry
// November 28, 2009
// Family Feud
//
// This program takes as input the question numbers, the questions, the answers,
// and the points. the question number is saved to the questionNumArray, the
// the question is saved to the questionNameArray, the answers are saved to
// the answersArray and the points are saved to the answersNumArray.
//
// This prgram will then and check if the user wants the rules, if yes the output
// will be the rules. The loop will then generate a random question, and take as
// input a guess from the user, the program will
// check if the guess is equal to one of the answers in answersArray, if so
// the loop will add the points in answersNumArray to the score, add one to the
// correct answers, and add one to found, the output will be the points won and
// "Correct". the loop will then check if found is equal to 1 if not one is
// added to strikes and the output is "Incorrect". The loop check if three
// questions have been asked, if so the users final score is the output,
// otherwise, the next question is asked and the score is the output. The loop
// will check if the users score is greater then the highscore, if so the
// output will be the players score to a file, and the the output to the screen
// will be "Congragulations you beat the highscore!" The loop will then check
// if the user wants to play again, if so the loop repeats. Otherwise the
// output will be "Thank-you for playing."
///////////////////////////////////////////////////////////////////////////////////
// Variables List:
// found = 0;
// count = 0;
// max = 0;
//int score = 0;
//int guess = 0;
//int repeat = 0;
//int errorCheck = 0;
//int correct = 0;
//int min = 0;
//int strikes = 0;
//int randomNum = 1;
//int highScore = 0;
//String playAgain = "";
//String name = "";
//String input = "";
//final int RANGE = 4;
//final int EMPTY = 0;
//final int MAX_INPUT = 34;
//final int GUESS_MAX = 8;
//final int MAX_CHECK = 7;
//final int ANSWERS_CORRECT = 5;
//final int MAX_QUESTION = 3;
//final int MAX_ARRAY = 35;
//final int NUM_RANGE = 7;
import java.io.*;
class FamilyFeud
{
public static void main (String args [])
throws java.io.IOException
{
int found = 0;
int count = 0;
int max = 0;
int score = 0;
int guess = 0;
int repeat = 0;
int errorCheck = 0;
int correct = 0;
int min = 0;
int strikes = 0;
int randomNum = 1;
int highScore = 0;
String playAgain = "";
String name = "";
String input = "";
final int RANGE = 4;
final int EMPTY = 0;
final int MAX_INPUT = 34;
final int GUESS_MAX = 8;
final int MAX_CHECK = 7;
final int ANSWERS_CORRECT = 5;
final int MAX_QUESTION = 3;
final int MAX_ARRAY = 35;
final int NUM_RANGE = 7;
int random [] = new int [RANGE];
int questionNumArray [] = new int [MAX_ARRAY];
int answersNumArray [] = new int [MAX_ARRAY];
String questionNameArray [] = new String [MAX_ARRAY];
String answersArray [] = new String [MAX_ARRAY];
// This loop will and check if the user wants the rules, if yes the output will
// be the rules. The loop will then generate a random question, and take as
// input a guess from the user, the program will
// check if the guess is equal to one of the answers in answersArray, if so
// the loop will add the points in answersNumArray to the score, add one to the
// correct answers, and add one to found, the output will be the points won and
// "Correct". the loop will then check if found is equal to 1 if not one is
// added to strikes and the output is "Incorrect". The loop check if three
// questions have been asked, if so the users final score is the output,
// otherwise, the next question is asked and the score is the output. The loop
// will check if the users score is greater then the highscore, if so the
// output will be the players score to a file, and the the output to the screen
// will be "Congragulations you beat the highscore!" The loop will then check
// if the user wants to play again, if so the loop repeats. Otherwise the
// output will be "Thank-you for playing."
do
{
FileReader fro = new FileReader ("survey.txt");
BufferedReader bfr = new BufferedReader (fro);
FileReader frt = new FileReader ("highScore.txt");
BufferedReader bhr = new BufferedReader (frt);
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
// This loop takes as input the question numbers, the questions, the answers,
// and the points. the question number is saved to the questionNumArray, the
// the question is saved to the questionNameArray, the answers are saved to
// the answersArray and the points are saved to the answersNumArray.
for (int countArray = 0; countArray <= MAX_INPUT; countArray ++)
{
input = bfr.readLine();
questionNumArray [countArray] = Integer.parseInt (input);
questionNameArray [countArray] = bfr.readLine();
answersArray [countArray] = bfr.readLine();
input = bfr.readLine();
answersNumArray [countArray] = Integer.parseInt (input);
}
fro.close();
System.out.println ("Welcome to Family Feud PHS Version");
input = bhr.readLine();
highScore = Integer.parseInt (input);
System.out.println ("The previous high score was: " + highScore);
frt.close();
System.out.println ("Can you beat it?");
System.out.println ("What is your Name?");
name = br.readLine();
System.out.println ("Do you want the rules?");
input = br.readLine ();
// This selection checks if input equals "yes" if so the output is the rules.
if (input.equalsIgnoreCase ("yes"))
{
System.out.println ("Now for the rules. A survey was given to one hundered" +
" people they each they each answered seven questio" +
"ns, the top five answers were taken. You will be as" +
"ked three of the questions, each question has five " +
"correct answers, each will have a point value assoc" +
"iated with it correspnding to how many people answe" +
"red it on the survey. The player will guess as to t" +
"he answer if correct the points the answer has will" +
"be added to the players score. After three incorrec" +
"t answers the question is over, after three questio" +
"n the players score is shown and the game is over.");
}
// This loop will generate a random question, and take as input a guess from
// the user, the program will check if the guess is equal to one of the answers
// in answersArray, if so the loop will add the points in answersNumArray to
// the score, add one to the correct answers, and add one to found, the output
// will be the points won and "Correct". the loop will then check if found is
// equal to 1 if not one is added to strikes and the output is "Incorrect". The
// loop check if three questions have been asked, if so the users final score
// is the output, otherwise the next question is asked and the score is output.
for (int countQuestion = 1; countQuestion <= MAX_QUESTION; countQuestion ++)
{
System.out.println ("\nRound: " + countQuestion);
randomNum = (int)(Math.random() * NUM_RANGE);
// This loop will take as input a guess from the user, the program will check
// if the guess is equal to one of the answers in answersArray, if so the
// loop will add the points in answersNumArray to the score, add one to the
// correct answers, and add one to found, the output will be the points won
// and "Correct". the loop will then check if found is equal to 1 if not one
// is added to strikes and the output is "Incorrect". The loop check if three
// questions have been asked, if so the users final score is the output,
// otherwise, the next question is asked.
while (strikes != MAX_QUESTION || correct != ANSWERS_CORRECT)
{
System.out.println (questionNameArray [randomNum * ANSWERS_CORRECT]);
min = ANSWERS_CORRECT * randomNum;
System.out.println ("What is your guess?");
input = br.readLine ();
max = min + RANGE;
// This loop will check if the guess is equal to one of the answers in
// answersArray, if so the loop will add the points in answersNumArray to
// the score, add one to the correct answers, and add one to found, the
// output will be the points won and "Correct".
for (int answerCheck = min; answerCheck <= max; answerCheck++)
{
// This Selection will check if the guess is equal to one of the answers
// in answersArray, if so the loop will add the points in answersNumArray
// to the score, add one to the correct answers, and add one to found, the
// output will be the points won and "Correct".
if (input.equalsIgnoreCase (answersArray [answerCheck]))
{
score += answersNumArray [answerCheck];
correct ++;
System.out.print ("Correct!");
System.out.println (" That was worth " +
answersNumArray [answerCheck] + " points.");
answersArray [answerCheck] = null;
count ++;
found ++;
}
}
// This selection will check if found is equal to 1, if not one is added to
// strikes and the output is "Incorrect".
if (found != 1)
{
System.out.println ("That was incorrect.");
strikes ++;
}
// This selection will check if correct is equal to ANSWERS_CORRECT, if so
// strikes will be equal to MAX_QUESTION, esle if strikes is equal to
// MAX_QUESTION, correct is will be equal to ANSWERS_CORRECT.
if (correct == ANSWERS_CORRECT)
{
strikes = MAX_QUESTION;
}
else if (strikes == MAX_QUESTION)
{
correct = ANSWERS_CORRECT;
}
found = EMPTY;
}
correct = EMPTY;
strikes = EMPTY;
System.out.println ("Your score is " + score + ".");
}
// This selection will check if the players score is higher then the
// highscore, if so the output will be the players score to a file, and the
// the output to the screen will be "Congragulations you beat the highscore!"
if (score > highScore)
{
FileWriter fw = new FileWriter ("highScore.txt");
fw.write (score + "\r\n");
fw.close();
System.out.println ("Congragulations you beat the highscore!");
}
System.out.println ("Would you like to play again?");
input = br.readLine ();
}
while (input.equalsIgnoreCase ("yes"));
System.out.println ("Thank-you for playing!");
}
}
This is the survey.txt file
1
What is your favourite breakfast cereal?
Frosted Flakes
17
1
What is your favourite breakfast cereal?
Special k
16
1
What is your favourite breakfast cereal?
Cheerios
14
1
What is your favourite breakfast cereal?
Cinnamin Toast Crunch
8
2
What is your favourite subject in school?
Gym
26
2
What is your favourite subject in school?
Science
11
2
What is your favourite subject in school?
Math
8
2
What is your favourite subject in school?
Art
7
2
What college or university do you want to attend?
None
6
3
What college or university do you want to attend?
University of Toronto
21
3
What college or university do you want to attend?
None
15
3
What college or university do you want to attend?
Durham College
9
3
What college or university do you want to attend?
Harvard
5
3
What college or university do you want to attend?
University
5
4
What is your favourite colour?
Blue
42
4
What is your favourite colour?
Red
21
4
What is your favourite colour?
Green
11
4
What is your favourite colour?
Purple
10
4
What is your favourite colour?
Black
3
5
What is your favourite shakespeare play?
Romeo and Juliet
35
5
What is your favourite shakespeare play?
None
30
5
What is your favourite shakespeare play?
Macbeth
13
5
What is your favourite shakespeare play?
King Lear
4
5
What is your Favourite Shakespeare play?
Hamlet
4
6
What is your Favourite brand of potato chips?
Lays
50
6
What is your Favourite brand of potato chips?
Doritos
20
6
What is your Favourite brand of potato chips?
None
7
6
What is your Favourite brand of potato chips?
Miss Vickie's
7
6
What is your Favourite brand of potato chips?
Sunchips
5
7
What is your Favourite Car Company?
Ford
16
7
What is your Favourite Car Company?
Lamborghini
12
7
What is your Favourite Car Company?
Toyota
12
7
What is your Favourite Car Company?
BMW
9
7
What is your Favourite Car Company?
General Motors
5
This is the highscore file
137
I keep getting this error:
java.lang.NumberFormatException: For input string: "None"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at FamilyFeud.main(FamilyFeud.java:128)
I cant figure out the solution what so ever
Please and thank you :)