Error on command prompt

public class Date
{
	   private int month; // 1-12
	   private int day;   // 1-31 based on month
	   private int year;  // any year
	 
	   // constructor: call checkMonth to confirm proper value for month;
	   // call checkDay to confirm proper value for day
	   public Date( int theMonth, int theDay, int theYear )
	   {
	      month = theMonth; // validate month
	      year = theYear; // could validate year
	      day = checkDay( theDay ); // validate day 		  
	   } // end Date constructor
	 
	   public void setMonth(int theMonth)
	   {
	       month = theMonth;
	   }
	 
	   // utility method to confirm proper month value
	   public int getMonth()
	   {
	      if ( month > 0 && month <= 12 ) // validate month
	         return month;
	      return 0;	  
	   } // end method checkMonth
	 
	   // utility method to confirm proper day value based on month and year
	   private int checkDay( int testDay )
	   {
	      int daysPerMonth[] =
	         { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	 
	      // check if day in range for month
	      if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
	         return testDay;
	 
	      // check for leap year
	      if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
	           ( year % 4 == 0 && year % 100 != 0 ) ) )
	         return testDay;
	 
	      return 0;  // maintain object in consistent state	  
	   } // end method checkDay
	 
	   // return a String of the form month/day/year
	   public String toString()
	   {
	      return String.format( "%d/%d/%d", month, day, year );	  
	   } // end method toString
	   
} // end class Date

Open in new window


Error on command prompt
main method found in class date, please define the main method as
public static void main(String[] args )

i just don't understand why i always get this error everytime on all java programming :
bakerule22Asked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:
In addition you don;'t wan tio name your class Date as there is standard class java.util.Date and other dates - you
don't wantbto have any more confusion about it
0
 
for_yanCommented:
You need to have method
public static voiid main(String [] args)
in the class which you mention inthecommand line

java MyClass ...

MyClass should have exactly this method
0
 
for_yanCommented:
If it does not have such method or it has diifferent signature - doesn't have arguments String[] args, or is not public or is not static, etc
then it will complain - youMUSThave this method
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CEHJCommented:
That error will only occur if you try to run a class without a main method *as an application*. Otherwise, it's perfectly legitimate
0
 
bakerule22Author Commented:
for example to make it work on my command prompt i put
} // end method toString 
public static void main(String[] args) 
{

}

Open in new window


not sure what to put in between
0
 
for_yanCommented:
This will be the method whwere you execution will start, so normally
you would say instantioate you most ioimportant class

In you case with Date (this is not a good example as I mentiond)
soemting like that:

} // end method toString 
public static void main(String[] args) 
{
Date dd = new Date(10,12,2011);
dd.setDay(..);
dd.print(..)
}

Open in new window


0
 
for_yanCommented:
In the applications with User Interface
you usually write class which implements say JFrame - that;s your main window
and you main method can be as simple as just creating this instance of this class:

like this:
} // end method toString 
public static void main(String[] args) 
{
new MyFrame("My Winodw");

}

Open in new window

0
 
bakerule22Author Commented:
ok
0
 
CEHJCommented:
The accepted answer is nothing to do with your problem
0
All Courses

From novice to tech pro — start learning today.