import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// THE SHELL THAT WILL RUN THE APPLICATION
// IMPORT ALL NECESSARY IOs
// THE CLASS DEFINITION
public class SportsSurvey
{
// CLASS VARIABLES
final static int numQuestions = 10;
// MAIN METHOD
public static void main(String args[])
{
// MAIN METHOD VARIABLES
int runChoice = -100; // SET AN OBVIOUS DEFAULT
int results[] = new int[numQuestions]; // INTERNAL VARIABLE TO HOLD CHUCK AND JAMES INFO
Question Data[] = new Question[10]; // THE MAIN OBJECT WHICH HOLDS ALL QUESTION INFO
Data = SportsSurvey.createQuestions(); // THIS STORES INFO TO IT
// LOOP CONTROLING ITERATIONS
do
{
do
{
runChoice = SportsSurvey.IndexDis();
// RUN DISPLAY
// runChoice = Survey.IndexDis();
// DISPLAY SHOULD RETURN WHICH ITEM TO EXECUTE
// (1) SURVEY
// (2) VEIW QUESTIONS
// (3) MODIFY QUESTIONS
}
while(!((runChoice < 4)&(runChoice > 0)));
switch(runChoice)
{
case 1: System.out.println("Run survey methods");
results = SportsSurvey.getInput(Data);
processData(results,Data);
break;
case 2: System.out.println("Run view questions methods");
SportsSurvey.ViewQuestions(Data);
break;
case 3: System.out.println("Run question reset");
SportsSurvey.ModQuest(Data);
break;
default:
System.out.println("runChoice has not been set to a legal choice");
}
// ERROR CHECKING
if(runChoice == -100)
System.out.println("Error in \"runChoice\" - variable is not reset!");
}
while( 1 == Integer.parseInt(JOptionPane.showInputDialog("Would another student like to take the survey?\n(1) Continue\n(2)Exit")));
SportsSurvey.printOutput(Data);
System.exit(0);
}
static int prompt(int i, Question[] Data)
{
int answer = 1;
String quest = Data[i].text;
String ans1 = Data[i].answer[0];
String ans2 = Data[i].answer[1];
String ans3 = Data[i].answer[2];
String ans4 = "Other";
do
{
if(!((answer < 5)&(answer > 0)))
JOptionPane.showMessageDialog(null, "Not a valid choice!", "Question" + (i+1), JOptionPane.INFORMATION_MESSAGE);
answer = (Integer.parseInt(JOptionPane.showInputDialog(quest + "\n 1."+ ans1 +"\n 2. " + ans2 +" \n 3. "+ ans3 +" \n 4." + ans4)));
}
while(!((answer < 5)&(answer > 0)));
return answer;
}
static int IndexDis()
{
String str = JOptionPane.showInputDialog("Please pick a number from the catagories: \n 1. Take Survey \n 2. View Survey Qustions \n 3. Add New Survey Questions");
int num1 = Integer.parseInt( str );
return num1;
}
static int[] getInput(Question [] Data)
{
int numberOfQuestions = 10;
int results[] = new int[numberOfQuestions];
//I AM CALLING ROB'S PROMPT AND ASKING THE ANSWER
for(int j = 0; j < 10; j++)
{
results[j] = prompt(j, Data);//CALL ROB'S FUNCTION
}
return results;
}
// STORE ALL THE INFO INTO THE DATA ARRAY
public static Question[] createQuestions()
{
Question [] Data = new Question[10];
for(int i = 0; i < Data.length; i++)
Data[i] = new Question();
Data[0].text ="Who is the best QB in the NFL?";
Data[0].answer[0] ="Donavan Mcnabb";
Data[0].answer[1] ="Peyton Manning";
Data[0].answer[2] ="Steve McNair";
Data[0].answer[3] ="Other";
Data[1].text ="Who has the best shot in the NBA?";
Data[1].answer[0] ="Iverson ";
Data[1].answer[1] ="Garnett";
Data[1].answer[2] ="McGrady ";
Data[1].answer[3] ="Other";
Data[2].text ="What MLB player hits hardest?";
Data[2].answer[0] ="Barry Bonds";
Data[2].answer[1] ="Albert Pujols ";
Data[2].answer[2] ="Todd Helton";
Data[2].answer[3] ="Other";
Data[3].text ="Who is the best rookie in the NHL?";
Data[3].answer[0] ="Patrice Bergeron";
Data[3].answer[1] ="Trent Hunter";
Data[3].answer[2] ="Michael Ryder";
Data[3].answer[3] ="Other";
Data[4].text ="Who is the best golfer in the PGA?";
Data[4].answer[0] ="Vijay Singh";
Data[4].answer[1] ="Tiger Woods";
Data[4].answer[2] ="Ernie Els";
Data[4].answer[3] ="Other";
Data[5].text ="Who is the best female tennis player?";
Data[5].answer[0] ="Venus Williams";
Data[5].answer[1] ="Serena Williams";
Data[5].answer[2] ="Anna Kournikova";
Data[5].answer[3] ="Other";
Data[6].text ="Who is the best male tennis player?";
Data[6].answer[0] ="Andre Agassi";
Data[6].answer[1] ="Marat Safin";
Data[6].answer[2] ="Andy Roddick";
Data[6].answer[3] ="Other";
Data[7].text ="Who is the strongest wrestler in the WWE?";
Data[7].answer[0] ="Bill Goldberg";
Data[7].answer[1] ="Brock Lesner";
Data[7].answer[2] ="Triple H";
Data[7].answer[3] ="Other";
Data[8].text ="What Nascar driver has the fastest car?";
Data[8].answer[0] ="Bobby Labonte";
Data[8].answer[1] ="Dale Earnhardt Jr.";
Data[8].answer[2] ="Jeff Gordon";
Data[8].answer[3] ="Other";
Data[9].text ="Who is the greatest athlete of all time?";
Data[9].answer[0] ="Michael Jordan";
Data[9].answer[1] ="Jim Thorpe";
Data[9].answer[2] ="Bo Jackson";
Data[9].answer[3] ="Other";
return Data;
}
static void modifyQuestion(Question[] Data, int whichQ)
{
//Question input
Data[whichQ].text = JOptionPane.showInputDialog("enter the question");
//answer input
Data[whichQ].answer[0] = JOptionPane.showInputDialog("enter the first answer");
Data[whichQ].answer[1] = JOptionPane.showInputDialog("enter the second answer");
Data[whichQ].answer[2] = JOptionPane.showInputDialog("enter the third answer");
Data[whichQ].answer[3] = JOptionPane.showInputDialog("enter the fourth answer");
}
static void ViewQuestions(Question[] Data)
{
JOptionPane.showMessageDialog(null, Data[0].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[1].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[2].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[3].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[4].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[5].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[6].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[7].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[8].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, Data[9].text, "View Questions", JOptionPane.PLAIN_MESSAGE);
}
static void ModQuest(Question[] data)
{
String str = JOptionPane.showInputDialog("Please pick a question to modify: \n"
+ "1." + data[0].text +"\n"
+ "2." + data[1].text +"\n"
+ "3." + data[2].text +"\n"
+ "4." + data[3].text +"\n"
+ "5." + data[4].text +"\n"
+ "6." + data[5].text +"\n"
+ "7." + data[6].text +"\n"
+ "8." + data[7].text +"\n"
+ "9." + data[8].text +"\n"
+ "10." + data[9].text +"\n");
int num1 = Integer.parseInt( str );
SportsSurvey.modifyQuestion(data, num1-1);
// System.out.println("The question to modify is: " + num1);
}
static void processData(int results[], Question[] Data)
{
for(int i = 0; i < Data.length; i++)
{
{
Data[i].ansTimes[results[i] - 1] = Data[i].ansTimes[results[i] - 1] + 1;
}
Data[i].iterations++;
}
}
// SHOW THE RESULTS OF THE SURVEY
static void printOutput(Question[] Data){
for (int i = 0; i < 10; i++){
JOptionPane.showMessageDialog(null, "This answer for question " + (i+1) + ",\n"
+ Data[i].answer[0] + " came up " + ((float)(Data[i].ansTimes[0])/Data[i].iterations)*100.0 + "% of the time.\n"
+ Data[i].answer[1] + " came up " + ((float)(Data[i].ansTimes[1])/Data[i].iterations)*100.0 + "% of the time.\n"
+ Data[i].answer[2] + " came up " + ((float)(Data[i].ansTimes[2])/Data[i].iterations)*100.0 + "% of the time.\n"
+ Data[i].answer[3] + " came up " + ((float)(Data[i].ansTimes[3])/Data[i].iterations)*100.0 + "% of the time.\n", "Results", JOptionPane.PLAIN_MESSAGE);
}
}
}