Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1.     public void addQuestion()
  2.     {
  3.         boolean checkCat = false;
  4.         Scanner scan = new Scanner(System.in);
  5.        
  6.         System.out.println("Enter the author of the question: ");
  7.        
  8.         String author = scan.nextLine();
  9.         String category;
  10.         while(!checkCat)
  11.         {
  12.             System.out.println("Enter the category of the question: ");
  13.            
  14.             category = scan.nextLine();
  15.            
  16.             for (Category c : Category.values()) {
  17.                 if (c.name().equals(category)) {
  18.                     checkCat =  true;
  19.                 }
  20.             }
  21.            
  22.             if(!checkCat)
  23.             {
  24.                 System.out.println("The category must be one of these");
  25.                 for(Category c : Category.values())
  26.                 {
  27.                     System.out.println(c);
  28.                 }
  29.             }
  30.         }
  31.        
  32.         System.out.println("Enter the statement of the question: ");
  33.        
  34.         String statement = scan.nextLine();
  35.        
  36.         System.out.println("Enter the answer of the question: ");
  37.        
  38.         String answer = scan.nextLine();
  39.  
  40.         Question q = new Question(author, category, statement, answer); // <---- "Change category to Category"
  41.         addQuestion(q);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement