title: How to make a program ask for a input date multiple times if wrong
body: <p>hi im trying to fix this program, </p>
  
  <p>Write a Java program that displays the calendar of any month of any year between 1900 and 2099.   </p>
  
  <p>The program must:<br>
  1. Prompt the user for a specific month with a meaningful message.</p>
  
  <ol start="2">
  <li>If the input value is a valid date (i.e. 3 characters designating the desired month (i.e. JAN, FEB, ..., in any combination of lower and upper case letters, followed by a space and an integer between 1900 and 2099), then the calendar for the given date must be displayed </li>
  </ol>
  
  <p>2.1. If the input value is not a valid date, the user must be informed that date was not acceptable, and then be prompted again for another date. If more than three consecutive erroneous dates are given, the program must be terminated with an appropriate error message.</p>
  
  <p>2.2. After displaying the calendar, the program must ask whether or not the user wants to enter another date (Do you want to continue?)</p>
  
  <p>2.3. The user must answer either yes, no, y or n, in any combination of lower and upper case letters </p>
  
  <p>2.4. If an invalid answer is given, the user must be informed that the answer was not acceptable, and then be prompted again for another answer. If more than three consecutive erroneous answers are given, the program must be terminated with an appropriate error message </p>
  
  <p>2.5. If the answer in step 2.2, is Yes (in any allowed form) the program must continue from step 1. If the answer is No (in any allowed form) the program must terminate with a message informing that the program is terminated normally. </p>
  
  <ol start="3">
  <li><p>All input must be done using an Scanner object i.e. Scanner kb = new Scanner (System.in); </p></li>
  <li><p>All output should be done using System.out.print or System.out.println </p></li>
  </ol>
  
  <p>so far i have gotten up to 2.1 my if statement in the program tells the user that the date was wrong however i am struggling how to then ask the user for another date, and if the user keeps putting in an incorrect date doing this 3 times before terminating the program, and if the user enters the right date, continuing to print the calendar.</p>
  
  <p>this is what i have so far </p>
  
  <pre><code>public static int getMonthNumber(String s) {
      if (s.equalsIgnoreCase("jan")) {
          return 1;
      }
      if (s.equalsIgnoreCase("feb")) {
          return 2;
      }
      if (s.equalsIgnoreCase("mar")) {
          return 3;
      }
      if (s.equalsIgnoreCase("apr")) {
          return 4;
      }
      if (s.equalsIgnoreCase("may")) {
          return 5;
      }
      if (s.equalsIgnoreCase("jun")) {
          return 6;
      }
      if (s.equalsIgnoreCase("jul")) {
          return 7;
      }
      if (s.equalsIgnoreCase("aug")) {
          return 8;
      }
      if (s.equalsIgnoreCase("sep")) {
          return 9;
      }
      if (s.equalsIgnoreCase("oct")) {
          return 10;
      }
      if (s.equalsIgnoreCase("nov")) {
          return 11;
      }
      if (s.equalsIgnoreCase("dec")) {
          return 12;
      } else {
          System.out.println("Not valid month!");
  
      }
      return 0;
  }
  
      public static int getDaysIn(int month, int year) {
      switch (month) {
          case 1:
              return 31;
          case 2:
              if (isLeapYear(month)) {
                  return 28;
              } else {
                  return 29;
              }
          case 3:
              return 31;
          case 4:
              return 30;
          case 5:
              return 31;
          case 6:
              return 30;
          case 7:
              return 31;
          case 8:
              return 31;
          case 9:
              return 30;
          case 10:
              return 31;
          case 11:
              return 30;
          case 12:
              return 31;
          default:
              return -1;
      }
  }
  
      public static boolean isLeapYear(int year) {
      int month = 0;
      int s = getDaysIn(month, year);
      return year % 4 == 0 &amp;&amp; (year % 100 != 0) || (year % 400 == 0);
  }
  
      public static String getMonthName(int month) {
      switch (month) {
          case 1:
              return "January";
          case 2:
              return "February";
          case 3:
              return "March";
          case 4:
              return "April";
          case 5:
              return "May";
          case 6:
              return "June";
          case 7:
              return "July";
          case 8:
              return "August";
          case 9:
              return "September";
          case 10:
              return "October";
          case 11:
              return "November";
          case 12:
              return "December";
          default:
              return "Invalid month.";
      }
      }
  
      public static int getStartDay(int month, int year) {
      int days = 0;
      for (int i = 1900; i &lt; year; i++) {
          days = days + 365;
          if (isLeapYear(i)) {
              days = days + 1;
  
          }
      }
      for (int i = 1; i &lt; month; i++) {
          days = days + getDaysIn(i, year);
      }
      int startday = (days % 7) + 2;
      return startday;
  
  }
  
      public static void displayCalendar(int month, int year) {
      String monthName = getMonthName(month);
      int startDay = getStartDay(month, year);
      int monthDays = getDaysIn(month, year);
  
      System.out.println("   Sun   Mon   Tue   Wed   Thu   Fri   Sat");
      int weekDay = startDay - 1;
      for (int i = 1; i &lt;= startDay; i = i + 1) {
          System.out.print("    ");
      }
      for (int x = 1; x &lt;= monthDays; x++) {
          weekDay = weekDay + 1;
          if (weekDay &gt; 7) {
              System.out.println();
              weekDay = 1;
          }
          System.out.format("   %3d", x);
      }
      if (weekDay &gt; 7) {
          System.out.println();
      }
  }
  
      public static void main(String[] args) {
      Scanner scan = null;
      Scanner kb = new Scanner(System.in);
      System.out.print("Give the first three letters of a month and enter the year: ");
      System.out.print(" ");
      String month;
      int year;
      month = kb.next();
      year = kb.nextInt();
      int yearno = year;
      int monthno = getMonthNumber(month);
      if (year &gt; 2099) 
          System.out.println("                 Invalid Year!");
  
      if (year &lt; 1900);
          System.out.println("                 Invalid Year!"); 
  
  
  
       System.out.println();
      displayCalendar(monthno, yearno);
      System.out.println();
      System.out.println();
      System.out.println("Do you want to continue? y/n ");
  </code></pre>
  
  <p>if the year is wrong it prints invalid year, but now m stuck on how to ask again 3 ties before ending the program/ continuing if the user enters the right date on one of the 3 tries. so far with my program, if the user enters a valid date the  correct calender is printed</p>