Advertisement
advictoriam

Untitled

Jan 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.regex.*;
  2. public class QuizCheck
  3. {
  4.    /**
  5.       Checks whether a string of quiz answers is valid. It must
  6.       contain an answer A, B, C, or D for each expected answer, or an
  7.       X to indicate that no answer was provided.
  8.       @param input the answer string
  9.       @param questions the number of questions in the string
  10.       @return true if the string was valid, false otherwise
  11.    */
  12.    public static boolean checkInputs(String input, int questions)
  13.    {
  14.       if(input.length() != questions){return false;}
  15.       if(input.length() != 0)
  16.       {
  17.         for(int i = 0; i < input.length(); i++)
  18.         {
  19.            switch(input.charAt(i))
  20.            {
  21.             case 'A':
  22.                break;
  23.             case 'B':
  24.                break;
  25.             case 'C':
  26.                break;
  27.             case 'D':
  28.                break;
  29.             case 'X':
  30.                break;
  31.             default:
  32.                return false;
  33.            }
  34.         }
  35.       }
  36.       return true;
  37.    }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement