title: Technical: program not working as expected (exceptions, arrays)
body: <p>I am making a program that is a scheduler. It is not working properly. I want three things:</p>
  <h3>1) Program keep asking until the array appointmentTime has no any empty (null) elements.</h3>
  <h3>2) If entered time is not between 1 and 6 [including], throw appropriate error.</h3>
  <h3>3) Throw another error if a time slot is already reserved.</h3>
  <p>Here is the code: for Scheduler class</p>
  <pre><code>    import java.util.Scanner;
      import java.lang.*;
      import java.io.*;
      import java.util.Arrays;
      
      public class Scheduler {
  
      /**
       * Writes a program that allows students to schedule appointments at either
       * 1, 2, 3, 4, 5, or 6 o’clock p. m.
       * 
       * @param args
       */
      public static void main(String[] args) {
          Scanner kbd = new Scanner(System.in);
  
          String[] appointmentTime = new String[6];
  
          int time;
          String name;
          boolean Continue;
          int temp;
  
          try {
              do {
  
                  System.out.println(&quot;\nEnter your name&quot;);
                  name = kbd.next();
  
                  System.out.println(&quot;Which time slot would you like to chose?&quot;);
                  time = kbd.nextInt();
  
                  if (appointmentTime[time - 1] == null &amp;&amp; time &lt; 0 &amp;&amp; time &gt; 6) {
                      appointmentTime[time - 1] = name;
                      System.out.println(time + &quot; is added to slot &quot;
                              + appointmentTime[time]);
  
                  } else if (appointmentTime[time - 1] != null) {
                      throw new TimeInUseException();
  
                  } else if (time &lt; 0 &amp;&amp; time &gt; 7) {
                      throw new InvalidTimeException();
                  }
  
              } while (appointmentTime[time - 1] == null);
  
              // Final stage: printing
              System.out.println(&quot;Schedule:&quot;);
              for (int i = 0; i &lt; appointmentTime.length; i++) {
  
                  System.out.println((i + 1) + &quot;PM: \t&quot;
                          + appointmentTime[i].toString());
  
              }
  
          } catch (InvalidTimeException e) {
              System.out.println(e.getMessage());
              System.out.println(&quot;Enter another time&quot;);
          } catch (TimeInUseException ex) {
              System.out.println(ex.getMessage());
              System.out.println(&quot;Enter another time&quot;);
          } catch (ArrayIndexOutOfBoundsException ex1) {
              System.out.println(ex1.getMessage());
          } catch (NullPointerException ex2) {
              System.out.println(ex2.getMessage());
          }
  
      }
  
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>Enter your name
  1
  Which time slot would you like to chose?
  1
  
  Enter your name
  2
  Which time slot would you like to chose?
  2
  
  Enter your name
  3
  Which time slot would you like to chose?
  3
  
  Enter your name
  4
  Which time slot would you like to chose?
  4
  
  Enter your name
  5
  Which time slot would you like to chose?
  5
  
  Enter your name
  6
  Which time slot would you like to chose?
  6
  
  Enter your name
  7
  Which time slot would you like to chose?
  7
  6
  </code></pre>
  <p>It does not stop at 6</p>