Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ActualWK8Assignment;
- import javax.swing.*;
- public class Quiz {
- public static void main(String[] args) {
- //Declare variables
- int answer, totalAsked = 0, correct = 0;
- String entry;
- //Declare questions
- String q1 = "Who won Super Bowl 40\n";
- String q2 = "When is the last time the Pirates won the World Series\n";
- String q3 = "Who is the captain of the Pens\n";
- String q4 = "When was Pittsburgh founded\n";
- String q5 = "When was Robert Morris University founded\n";
- //Answers
- String a1 = "Steelers", a2 = "1979", a3 = "Crosby", a4 = "1758", a5 = "1921";
- //Build String List of out answers
- String answerList = "(1)" + a1 + "\n" +
- "(2)" + a2 + "\n" +
- "(3)" + a3 + "\n" +
- "(4)" + a4 + "\n" +
- "(5)" + a5 + "\n" +
- "(6)" + "All of the above" + "\n";
- entry = JOptionPane.showInputDialog(null, q1 + answerList);
- answer = Integer.parseInt(entry);
- while(answer < 1 || answer > 6)
- {
- entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q1 + answerList);
- answer = Integer.parseInt(entry);
- }
- //Used to keep a count of all the questions that were asked
- ++totalAsked;
- //Conditional Statement
- if(answer != 1)
- {
- JOptionPane.showMessageDialog(null, "Sorry, answer was " + a1);
- }
- else
- {
- //Keep track of how many questions were correct
- ++correct;
- JOptionPane.showMessageDialog(null, "Awesome Job!");
- }
- //----------------------- ends question 1 feed -----------------------
- entry = JOptionPane.showInputDialog(null, q2 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- while(answer < 1 || answer > 6)
- {
- entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q2 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- }
- //Used to keep a count of all the questions that were asked
- ++totalAsked;
- //Conditional Statement
- if(answer != 2)//Mod line
- {
- JOptionPane.showMessageDialog(null, "Sorry, answer was " + a2); //Mod Line
- }
- else
- {
- //Keep track of how many questions were correct
- ++correct;
- JOptionPane.showMessageDialog(null, "Awesome Job!");
- }
- //----------------------- ends question 1 feed -----------------------
- entry = JOptionPane.showInputDialog(null, q3 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- while(answer < 1 || answer > 6)
- {
- entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q3 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- }
- //Used to keep a count of all the questions that were asked
- ++totalAsked;
- //Conditional Statement
- if(answer != 3)//Mod line
- {
- JOptionPane.showMessageDialog(null, "Sorry, answer was " + a3); //Mod Line
- }
- else
- {
- //Keep track of how many questions were correct
- ++correct;
- JOptionPane.showMessageDialog(null, "Awesome Job!");
- }
- //----------------------- ends question 1 feed -----------------------
- entry = JOptionPane.showInputDialog(null, q4 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- while(answer < 1 || answer > 6)
- {
- entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q4 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- }
- //Used to keep a count of all the questions that were asked
- ++totalAsked;
- //Conditional Statement
- if(answer != 4)//Mod line
- {
- JOptionPane.showMessageDialog(null, "Sorry, answer was " + a4); //Mod Line
- }
- else
- {
- //Keep track of how many questions were correct
- ++correct;
- JOptionPane.showMessageDialog(null, "Awesome Job!");
- }
- //----------------------- ends question 1 feed -----------------------
- entry = JOptionPane.showInputDialog(null, q5 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- while(answer < 1 || answer > 6)
- {
- entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q5 + answerList); //Mod line
- answer = Integer.parseInt(entry);
- }
- //Used to keep a count of all the questions that were asked
- ++totalAsked;
- //Conditional Statement
- if(answer != 5)//Mod line
- {
- JOptionPane.showMessageDialog(null, "Sorry, answer was " + a5); //Mod Line
- }
- else
- {
- //Keep track of how many questions were correct
- ++correct;
- JOptionPane.showMessageDialog(null, "Awesome Job!");
- }
- //----------------------- ends question 1 feed -----------------------
- //Final part to display a summary
- JOptionPane.showMessageDialog(null, "You got " + correct + " right out of " + totalAsked + "\nScore = " + (correct * 100 / totalAsked) + "%" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement