Advertisement
Guest User

java help

a guest
Oct 27th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.69 KB | None | 0 0
  1. package ActualWK8Assignment;
  2.  
  3. import javax.swing.*;
  4.  
  5. public class Quiz {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         //Declare variables
  10.         int answer, totalAsked = 0, correct = 0;
  11.         String entry;
  12.  
  13.         //Declare questions
  14.         String q1 = "Who won Super Bowl 40\n";
  15.         String q2 = "When is the last time the Pirates won the World Series\n";
  16.         String q3 = "Who is the captain of the Pens\n";
  17.         String q4 = "When was Pittsburgh founded\n";
  18.         String q5 = "When was Robert Morris University founded\n";
  19.  
  20.         //Answers
  21.         String a1 = "Steelers", a2 = "1979", a3 = "Crosby", a4 = "1758", a5 = "1921";
  22.  
  23.         //Build String List of out answers
  24.         String answerList = "(1)" + a1 + "\n" +
  25.                 "(2)" + a2 + "\n" +
  26.                 "(3)" + a3 + "\n" +
  27.                 "(4)" + a4 + "\n" +
  28.                 "(5)" + a5 + "\n" +
  29.                 "(6)" + "All of the above" + "\n";
  30.  
  31.         entry = JOptionPane.showInputDialog(null, q1 + answerList);
  32.         answer = Integer.parseInt(entry);
  33.         while(answer < 1 || answer > 6)
  34.         {
  35.             entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q1 + answerList);
  36.             answer = Integer.parseInt(entry);
  37.         }
  38.  
  39.         //Used to keep a count of all the questions that were asked
  40.         ++totalAsked;
  41.  
  42.         //Conditional Statement
  43.         if(answer != 1)
  44.         {
  45.             JOptionPane.showMessageDialog(null, "Sorry, answer was " + a1);
  46.         }
  47.         else
  48.         {
  49.             //Keep track of how many questions were correct
  50.             ++correct;
  51.             JOptionPane.showMessageDialog(null, "Awesome Job!");
  52.         }
  53.         //----------------------- ends question 1 feed -----------------------
  54.         entry = JOptionPane.showInputDialog(null, q2 + answerList); //Mod line
  55.         answer = Integer.parseInt(entry);
  56.         while(answer < 1 || answer > 6)
  57.         {
  58.             entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q2 + answerList); //Mod line
  59.             answer = Integer.parseInt(entry);
  60.         }
  61.  
  62.         //Used to keep a count of all the questions that were asked
  63.         ++totalAsked;
  64.  
  65.         //Conditional Statement
  66.         if(answer != 2)//Mod line
  67.         {
  68.             JOptionPane.showMessageDialog(null, "Sorry, answer was " + a2); //Mod Line
  69.         }
  70.         else
  71.         {
  72.             //Keep track of how many questions were correct
  73.             ++correct;
  74.             JOptionPane.showMessageDialog(null, "Awesome Job!");
  75.         }
  76.         //----------------------- ends question 1 feed -----------------------
  77.         entry = JOptionPane.showInputDialog(null, q3 + answerList); //Mod line
  78.         answer = Integer.parseInt(entry);
  79.         while(answer < 1 || answer > 6)
  80.         {
  81.             entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q3 + answerList); //Mod line
  82.             answer = Integer.parseInt(entry);
  83.         }
  84.  
  85.         //Used to keep a count of all the questions that were asked
  86.         ++totalAsked;
  87.  
  88.         //Conditional Statement
  89.         if(answer != 3)//Mod line
  90.         {
  91.             JOptionPane.showMessageDialog(null, "Sorry, answer was " + a3); //Mod Line
  92.         }
  93.         else
  94.         {
  95.             //Keep track of how many questions were correct
  96.             ++correct;
  97.             JOptionPane.showMessageDialog(null, "Awesome Job!");
  98.         }
  99.         //----------------------- ends question 1 feed -----------------------
  100.         entry = JOptionPane.showInputDialog(null, q4 + answerList); //Mod line
  101.         answer = Integer.parseInt(entry);
  102.         while(answer < 1 || answer > 6)
  103.         {
  104.             entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q4 + answerList); //Mod line
  105.             answer = Integer.parseInt(entry);
  106.         }
  107.  
  108.         //Used to keep a count of all the questions that were asked
  109.         ++totalAsked;
  110.  
  111.         //Conditional Statement
  112.         if(answer != 4)//Mod line
  113.         {
  114.             JOptionPane.showMessageDialog(null, "Sorry, answer was " + a4); //Mod Line
  115.         }
  116.         else
  117.         {
  118.             //Keep track of how many questions were correct
  119.             ++correct;
  120.             JOptionPane.showMessageDialog(null, "Awesome Job!");
  121.         }
  122.         //----------------------- ends question 1 feed -----------------------
  123.         entry = JOptionPane.showInputDialog(null, q5 + answerList); //Mod line
  124.         answer = Integer.parseInt(entry);
  125.         while(answer < 1 || answer > 6)
  126.         {
  127.             entry = JOptionPane.showInputDialog(null, "Sorry, answer must be a number 1 through 6\n" + q5 + answerList); //Mod line
  128.             answer = Integer.parseInt(entry);
  129.         }
  130.  
  131.         //Used to keep a count of all the questions that were asked
  132.         ++totalAsked;
  133.  
  134.         //Conditional Statement
  135.         if(answer != 5)//Mod line
  136.         {
  137.             JOptionPane.showMessageDialog(null, "Sorry, answer was " + a5); //Mod Line
  138.         }
  139.         else
  140.         {
  141.             //Keep track of how many questions were correct
  142.             ++correct;
  143.             JOptionPane.showMessageDialog(null, "Awesome Job!");
  144.         }
  145.         //----------------------- ends question 1 feed -----------------------
  146.        
  147.         //Final part to display a summary
  148.         JOptionPane.showMessageDialog(null, "You got " + correct + " right out of " + totalAsked + "\nScore = " + (correct * 100 / totalAsked) + "%" );
  149.     }
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement