SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top