title: Java program to calculate and display tomorrow's date
body: <p>I'm attempting to write a program that receives a present date input, and then displays tomorrow's date.
  I think it's almost complete, but something is going wrong when I test the present date variables to maxDays. I never get the correct date for tomorrow.</p>
  
  <p>I think the problem with my code lies in this part. Thanks for taking a look!</p>
  
  <pre><code>if (((presentDay &gt; maxDays || presentDay &lt; 1)) || (presentMonth &gt; 12)
              || (presentYear &lt; 0)) {
          JOptionPane.showMessageDialog(null, "Please enter valid date \n\n"
                  + "consider number of days in each month\n"
                  + "entries must be greater than or equal to 1");
      } else {
  
          if (presentDay == maxDays) {
              if (presentMonth == 12) {
                  tmrwDay = 1;
                  tmrwMonth = 1;
                  tmrwYear = presentYear++;
              } else {
                  tmrwDay = 1;
                  tmrwMonth = presentMonth++;
                  tmrwYear = presentYear;
              }
          } else {
              tmrwDay = presentDay++;
              tmrwMonth = presentMonth;
              tmrwYear = presentYear;
          }
  
          displayTmrwDate(tmrwDay, tmrwMonth, tmrwYear);
  
      }
  </code></pre>
  
  <p>Here is the full program:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class Lab5 extends JFrame implements ActionListener {
  
  private JTextField dayTextField, monthTextField, yearTextField;
  private JLabel nextDateCalculatorLabel, presentDayLabel,
          presentMonthLabel, presentYearLabel;
  
  public static void main(String[] args) {
      Lab5 frame = new Lab5();
      frame.pack();
      frame.setSize(300, 200);
      frame.createGUI();
      frame.setLocationRelativeTo(null);  //centers the frame
      frame.setVisible(true);
  }
  
  private void createGUI() {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      Container window = getContentPane();
      window.setLayout(new FlowLayout());
  
      nextDateCalculatorLabel = new JLabel("- - - - -" + "  "
              + "N e x t" + "  " + "D a y" + "  " + "C a l c u l a t o r"
              + "  " + "- - - - -");
      window.add(nextDateCalculatorLabel);
  
      presentDayLabel = new JLabel("Enter Present Day:");
      window.add(presentDayLabel);
  
      dayTextField = new JTextField(5);
      window.add(dayTextField);
      dayTextField.addActionListener(this);
  
      presentMonthLabel = new JLabel("Enter Present Month:");
      window.add(presentMonthLabel);
  
      monthTextField = new JTextField(5);
      window.add(monthTextField);
      monthTextField.addActionListener(this);
  
      presentYearLabel = new JLabel("Enter Present Year:");
      window.add(presentYearLabel);
  
      yearTextField = new JTextField(5);
      window.add(yearTextField);
      yearTextField.addActionListener(this);
  }
  
  @Override
  public void actionPerformed(ActionEvent event) {
      int presentDay, presentMonth, presentYear;
      int maxDays, tmrwDay, tmrwMonth, tmrwYear;
      String inputString;
  
      inputString = dayTextField.getText();
      presentDay = Integer.parseInt(inputString);
  
      inputString = monthTextField.getText();
      presentMonth = Integer.parseInt(inputString);
  
      inputString = yearTextField.getText();
      presentYear = Integer.parseInt(inputString);
  
      maxDays = calcMaxDays(presentMonth, presentYear);
  
      if (((presentDay &gt; maxDays || presentDay &lt; 1)) || (presentMonth &gt; 12)
              || (presentYear &lt; 0)) {
          JOptionPane.showMessageDialog(null, "Please enter valid date \n\n"
                  + "consider number of days in each month\n"
                  + "entries must be greater than or equal to 1");
      } else {
  
          if (presentDay == maxDays) {
              if (presentMonth == 12) {
                  tmrwDay = 1;
                  tmrwMonth = 1;
                  tmrwYear = presentYear++;
              } else {
                  tmrwDay = 1;
                  tmrwMonth = presentMonth++;
                  tmrwYear = presentYear;
              }
          } else {
              tmrwDay = presentDay++;
              tmrwMonth = presentMonth;
              tmrwYear = presentYear;
          }
  
          displayTmrwDate(tmrwDay, tmrwMonth, tmrwYear);
  
      }
  
  }
  
  private int calcMaxDays(int m, int y) {
      int maxDays = 0;
  
      switch (m) {
  
          case 1: case 3: case 5: case 7: case 8: case 10: case 12:
              maxDays = 31;
              break;
  
          case 4: case 6: case 9: case 11:
              maxDays = 30;
              break;
  
          case 2:
              if ((y % 400 == 0) || (y % 100 != 0 &amp;&amp; y % 4 == 0)) {
                  maxDays = 29;
              } else {
                  maxDays = 28;
              }
              break;
      }
  
      return maxDays;
  }
  
  private static void displayTmrwDate(int tD, int tM, int tY) {
      JOptionPane.showMessageDialog(null, "The Date Tomorrow is:\n"
              + tD + "/" + tM + "/" + tY);
  }
  </code></pre>
  
  <p>}</p>