using dialog boxes :
input month in "99" form
date in "99" form
year = 2009
then display the date in 'MMM 99, 2009' form
otherwise, display 'invalid date'

Valid date
01-12 = Values for month
01-28 = for month - 2
01-30 = for months - 4,6,9,11
01-31 = for months - 1,3,5,7,8,10,12

Recommended Answers

All 5 Replies

Okay? So what do you have, and what error/compiler messages are you getting from it, or what is it doing that you don't expect, or vice-versa.

You will notice the terms and conditions of this site (which you agreed to when you signed up here), forbid us simply giving you a solution to your homework (as if we would, anyway).

Okay? So what do you have, and what error/compiler messages are you getting from it, or what is it doing that you don't expect, or vice-versa.

You will notice the terms and conditions of this site (which you agreed to when you signed up here), forbid us simply giving you a solution to your homework (as if we would, anyway).

thanks for everything...
by the way i already got the code...

import javax.swing.*;
class Midmp1
{
   public static void main(String[]args)
     {
         String month,day;  
         int monthint=0;
         int dayint = 0;
         month = JOptionPane.showInputDialog ("month: ");
          int error = 0;
          while (error == 0)
              {
                 error = 1;
                 try
                 {
     monthint = Integer.parseInt(month);
    }
    catch (NumberFormatException e)
    {
        error = 0;
        month = JOptionPane.showInputDialog("month: ");
     }
                 }  
       day = JOptionPane.showInputDialog("day: ");
  int error1 = 0;
          while (error1 == 0)
              {
                 error1 = 1;
                 try
                 {
    dayint = Integer.parseInt(day);
    }
    catch (NumberFormatException e)
    {
        error1 = 0;
        day = JOptionPane.showInputDialog("day: ");
     }
                 }  
       if (monthint > 12 || monthint <=0)
         {
              JOptionPane.showMessageDialog(null,"Invalid Date");
          }
       else if (dayint >31 || dayint <=0)
          {
                JOptionPane.showMessageDialog(null,"Invalid Date");
          }
       else if (monthint == 1 && dayint<=31)
         {
               JOptionPane.showMessageDialog(null,"Jan "+dayint+", "+"2009");
          }
       else if (monthint == 2 && dayint<=28 )
         {
              JOptionPane.showMessageDialog(null,"Feb "+dayint+", "+"2009");
          }
        else if (monthint ==3 && dayint<=31 )
         {
               JOptionPane.showMessageDialog(null,"Mar "+dayint+", "+"2009");
          }
        else if (monthint ==4&& dayint<=30)
          {
                JOptionPane.showMessageDialog(null,"Apr "+dayint+", "+"2009");
           }
        else if(monthint ==5&& dayint<=31)
           {
                JOptionPane.showMessageDialog(null,"May "+dayint+", "+"2009");
            } 
          else if(monthint ==6 && dayint<=30)
           {
                 JOptionPane.showMessageDialog(null,"Jun "+dayint+", "+"2009");
            }
           else if(monthint ==7 && dayint<=31)
           {
                JOptionPane.showMessageDialog(null,"Jul "+dayint+", "+"2009");
            }
           else if(monthint ==8 && dayint<=31)
           {
                JOptionPane.showMessageDialog(null,"Aug "+dayint+", "+"2009");
            }
            else if(monthint ==9 && dayint<=30)
           {
                 JOptionPane.showMessageDialog(null,"Sep "+dayint+", "+"2009");
            }
            else if(monthint ==10 && dayint<=30)
              {
                   JOptionPane.showMessageDialog(null,"Oct "+dayint+", "+"2009");
                }
           else if(monthint ==11 && dayint<=30)
             {
                   JOptionPane.showMessageDialog(null,"Nov "+dayint+", "+"2009");
              }
           else if(monthint ==12 && dayint<=31)
            {
                 JOptionPane.showMessageDialog(null,"Dec "+dayint+", "+"2009");                      }
           else if(monthint ==2 && dayint>28)
              {
                  JOptionPane.showMessageDialog(null,"Invalid Date");
              }
          else if (monthint <= 0 || dayint<=0)
              {
                  JOptionPane.showMessageDialog(null,"Invalid Date");
              }
          else if (dayint >30)
              {
                 if (monthint == 4)
                   {
                        JOptionPane.showMessageDialog(null,"Invalid Date");
                    }
                   if (monthint == 6)
                   {
                        JOptionPane.showMessageDialog(null,"Invalid Date");
                    }  
               if (monthint == 9)
                   {
                        JOptionPane.showMessageDialog(null,"Invalid Date");
                    }
                if (monthint == 11)
                   {
                        JOptionPane.showMessageDialog(null,"Invalid Date");
                    }
                }
System.exit(0);
  }
}

So someone gace you an ugl and, most likely error-prone clotz of a workaround, and you might pass your assignment. You still haven't learned anything, so your next assignment is only going to be that much more bewildering. I can only hope that you wind up working with those people that did your homework for you so they can continue doing your actual work for you. Hopefully, by then, you will both have learned a lesson.

Member Avatar for campbellm

Take a look at SimpleDateFormatter. It has a way to parse a Date from a String. Make sure you look at the "setLenient()" method in it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.