title: Validate User Input Using Java Chars and Strings
body: <p>I have seen this asked 2x, but the correct response I need has not been addressed.</p>
  
  <p>In this assessment,
   you will design and code a Java console application that
   validates the data 
  entry
    of a course code (like IT4782)
   and 
  report
   back if the
   course code is valid or
   not
   valid.
   The 
  application 
  uses the Java char
   and 
  String data types to implement
   the validation.
   You 
  can 
  use 
  either
   the
    Toolwire environment
   or your
   local 
  Java
   development
   environment
   to complete this 
  assignment.</p>
  
  <p>The requirements of
   this application are 
  as follows:
   The application is to read 
  a course code 
  entered 
  by the user
   from the
   keyboard.
   The course code
   is made 
  of 5 characters and should 
  follow
  these </p>
  
  <p>Rules:</p>
  
  <ul>
  <li>First
  character
  is  always
  an 
  upper
  case I
  or a lower
  case i</li>
  <li>Second character
  is always an upper
  case
  T or
  a lower
  case t</li>
  <li>Third,
  fourth,
  fifth,
  and sixth characters
  are always digits (0-
  9) 
  The application then validates the course code against
  above the rules and prints a
  message </li>
  </ul>
  
  <p>If the
  course code 
  is valid
   or not.
   If the course code is not
   valid,
   the application should print
   a message 
  explaining why
   the course 
  code is not
   valid.</p>
  
  <p>Output should look like this:
  <img src="https://i.stack.imgur.com/6UzYm.jpg" alt="Output should look like this"></p>
  
  <p>Here is my code, I cannot get the code to produce the pictured results. It outputs all the invalid messages.</p>
  
  <pre><code>package u4a1_validatecoursecode;
  
  import java.util.Scanner;
  
  public class U4A1_ValidateCourseCode {
  
      public static void main(String[] args) {
          // Larry Copy
          Scanner s = new Scanner(System.in);
          System.out.print("Enter a course code to validate (e.g. IT4782) : ");
          String code = s.nextLine();
          if (validateCode(code)) {
              System.out.println("Course code: " + "" + code + "" + " is valid.");
          } else {
              System.out.println("Not valid code");
          }
      }
  
      private static boolean validateCode(String code) {
          if (code.length() != 6) {
              return false;
          } else {
              //First character is always an upper case I or a lower case i
              if (code.charAt(0) != 'I' &amp;&amp; code.charAt(0) != 'i') {
                  return false;
              }
              System.out.println("integer is not an I or i");
  
              // Second character is always an upper case T or a lower case t
              if (code.charAt(1) != 'T' &amp;&amp; code.charAt(1) != 't') {
                  return false;
              }
              System.out.println("integer is not a T or t");
  
              // Third, fourth, fifth, and sixth characters are always digits (0-9)
              if (!Character.isDigit(code.charAt(2))) {
                  return false;
              }
              System.out.println("integer 3 is not a number");
  
              if (!Character.isDigit(code.charAt(3))) {
                  return false;
              }
              System.out.println("integer 4 is not a number");
  
              if (!Character.isDigit(code.charAt(4))) {
                  return false;
              }
              System.out.println("integer 5 is not a number");
  
              if (!Character.isDigit(code.charAt(5))) {
                  return false;
              }
              System.out.println("integer 6 is not a number");
              return false;
          }
      }
  }
  </code></pre>