import javax.swing.JOptionPane;
import java.util.Random;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Quizzer3
{
public static void main(String[] args) throws IOException
{
boolean mainEnd = false;
Object[] options = {"Continue", "Quit"};
while(!mainEnd)
{
int userOption = JOptionPane.showOptionDialog(null, "Welcome to Quizzer3! This program was designed to test your knowledge of official three letter Scrabble words.\nPress continue to proceed to the Quizzer.", "Quizzer3", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if(userOption == JOptionPane.NO_OPTION)
{
int userReply = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Quit Quizzer3", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if(userReply == JOptionPane.YES_OPTION)
{
mainEnd = true;
System.exit(0);
}
}
if(userOption == JOptionPane.YES_OPTION)
{
boolean quizEnd = false;
Random generator = new Random();
char[] vowels = {'A', 'E', 'I', 'O', 'U', 'Y'};
char[] consonants = {'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z'};
char[] letters = {'n', 'n', 'n'};
Object[] choices = {"It's good.", "It's phony!"};
boolean good = false;
String def;
FileReader fr = new FileReader("TWL_Dic_3.txt");
BufferedReader readWord = new BufferedReader(fr);
while(!quizEnd)
{
int letterGroup = generator.nextInt(22);
if(letterGroup < 6)
{
letters[0] = 'c';
letters[1] = 'v';
letters[2] = 'c';
}
if(letterGroup > 5 && letterGroup < 10)
{
letters[0] = 'v';
letters[1] = 'c';
letters[2] = 'v';
}
if(letterGroup > 9 && letterGroup < 13)
{
letters[0] = 'v';
letters[1] = 'v';
letters[2] = 'c';
}
if(letterGroup > 12 && letterGroup < 16)
{
letters[0] = 'c';
letters[1] = 'v';
letters[2] = 'v';
}
if(letterGroup > 15 && letterGroup < 18)
{
letters[0] = 'c';
letters[1] = 'c';
letters[2] = 'v';
}
if(letterGroup > 17 && letterGroup < 20)
{
letters[0] = 'v';
letters[1] = 'c';
letters[2] = 'c';
}
if(letterGroup == 20)
{
letters[0] = 'v';
letters[1] = 'v';
letters[2] = 'v';
}
if(letterGroup == 21)
{
letters[0] = 'c';
letters[1] = 'c';
letters[2] = 'c';
}
if(letters[0] == 'c')
letters[0] = consonants[generator.nextInt(21)];
else if(letters[0] == 'v')
letters[0] = vowels[generator.nextInt(6)];
if(letters[1] == 'c')
letters[1] = consonants[generator.nextInt(21)];
else if(letters[1] == 'v')
letters[1] = vowels[generator.nextInt(6)];
if(letters[2] == 'c')
letters[2] = consonants[generator.nextInt(21)];
else if(letters[2] == 'v')
letters[2] = vowels[generator.nextInt(6)];
String word = new String(letters);
int userChoice = JOptionPane.showOptionDialog(null, "Is this a word?\n" + word, "Is " + word + " a word?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, choices[1]);
if(userChoice == JOptionPane.CLOSED_OPTION)
{
quizEnd = true;
}
String testWord = readWord.readLine();
while(testWord != null)
{
if(testWord.startsWith(word))
{
good = true;
def = testWord.substring(4);
break;
}
testWord = readWord.readLine();
}
if(userChoice == JOptionPane.YES_OPTION && good == true)
JOptionPane.showMessageDialog(null, "Correct!\nYES, " + word + " is a word.", "IS a word", JOptionPane.INFORMATION_MESSAGE);
if(userChoice == JOptionPane.YES_OPTION && good == false)
JOptionPane.showMessageDialog(null, "Wrong!\nNO, " + word + " is not a word.", "NOT a word", JOptionPane.ERROR_MESSAGE);
if(userChoice == JOptionPane.NO_OPTION && good == false)
JOptionPane.showMessageDialog(null, "Correct!\nNO, " + word + " is not a word.", "NOT a word", JOptionPane.INFORMATION_MESSAGE);
if(userChoice == JOptionPane.NO_OPTION && good == true)
JOptionPane.showMessageDialog(null, "Wrong!\nYES, " + word + " is a word.", "IS a word", JOptionPane.ERROR_MESSAGE);
}
}
}
}
}