Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. package onlineQuiz;
  2. import java.util.Random;
  3.  
  4. public class QuestionBank
  5. {
  6.     Random question = new Random();
  7.     public int Question()
  8.     {
  9.         return question.nextInt(4);
  10.     }
  11.  
  12.     String questions[] = {
  13.     "The smallest prime number?",
  14.     "What is the area of triangle with base = 4 and height = 3?",
  15.     "What is the area of square with side = 5?",
  16.     "What is the square root of 144?",
  17.     "How many states are in the US?",
  18.     "How many continents are in the world?",
  19.     "In which year did man land on the moon?",
  20.     "How many colors in a rainbow?",
  21.     "How many colors in the US flag?",
  22.     "What is the square of 25?"};
  23.  
  24.     int answers[] = {2,6,25,12,50,7,1969,7,3,5};
  25.  
  26.     boolean CheckAswers(int useranswer, int questionnumber)
  27.     {
  28.         if(useranswer == questions[questionnumber])
  29.             return true;
  30.         else
  31.             return false;
  32.     }
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. package onlineQuiz;
  49.  
  50. import java.util.Scanner;
  51. import java.util.Random;
  52.  
  53. public class OnlineQuiz {
  54.  
  55.     /**
  56.      * @param args
  57.      */
  58.     public static void main(String[] args) {
  59.         // declare variable
  60.         int totalScore = 0;
  61.         Scanner input = new Scanner(System.in);
  62.         Random rng = new Random();
  63.         QuestionBank qb = new QuestionBank;
  64.         int useranswer = 0;
  65.        
  66.         int questionsasked[] = new int[5];
  67.        
  68.         for (int i=0;i<4;i++)
  69.         {
  70.             int nextnumber  = rng.nextInt(9);
  71.             boolean repeated = false;
  72.             for (int j=0;i<4;i++)
  73.             {
  74.                 if(nextnumber == questionsasked[j])
  75.                     repeated = true;
  76.             }
  77.             if(!repeated)
  78.                 questionasked[i] = nextnumber;
  79.         }
  80.        
  81.         for(int k=0;k<4;k++)
  82.         {
  83.             System.out.println((k+1)+". "+qb.questions[k]);
  84.             useranswer = input.nextInt();
  85.            
  86.             if(qb.CheckAnswer)
  87.                 score+=2;
  88.             else
  89.                 score-=1;
  90.         }
  91.        
  92.         System.out.println("\nFINAL SCORE: "+score +"/10");
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement