Results 1 to 9 of 9
  1. #1
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Question Calendar - problem in Cprompt

    Hi guys .
    i'm new here n' i'm also a new java programmer . i've done this java code for calendar .as i check run it into C prompt , there's no error there , when type
    java Date to see the result this >> " Exception in thread "main " java.lang.NoSuchMethodError:main << error will be shown !
    could you check the codes and tell me what's wrong with my program ?
    thanks.

    Java Code:
    public class Date
    {
    	private int month; 
    	private int day; 
    	private int year; 
    	
    	public Date( int theMonth, int theDay, int theYear )
    	{
    		month = checkMonth( theMonth ); 
    		year = theYear; 
    		day = checkDay( theDay ); 
    		
    		System.out.printf(
    			"Date object constructor for date %s\n", this );
    		} 
    		
    		private int checkMonth( int testMonth )
    		{
    			if ( testMonth > 0 && testMonth <= 12 ) 
    				return testMonth;
    			else 
    			{
    				System.out.printf(
    					"Invalid month (%d) set to 1.", testMonth );
    				return 1; 
    			} 
    		} 
    		
    		private int checkDay( int testDay )
    		{
    			int daysPerMonth[] =
    				{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    				
    			if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
    				return testDay;
    			
    			if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
    					( year % 4 == 0 && year % 100 != 0 ) ) )
    				return testDay;
    			
    			System.out.printf( "Invalid day (%d) set to 1.", testDay );
    			return 1; 
    		} 
    		
    		public String toString()
    		{
    			return String.format( "%d/%d/%d", month, day, year );
    		} 
    	}

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Your class definition is missing main method. Any class which begins the
    execution of any application must have an entry point i.e. main method which goes as follows

    public static void main(String arg[]){
    }

    or

    public static void main(String[] arg){
    }

  3. #3
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    so , can you rewrite this code please ?

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    public class Date
    {
    	private int month;
    	private int day;
    	private int year;
    
    	public Date( int theMonth, int theDay, int theYear )
    	{
    		month = checkMonth( theMonth );
    		year = theYear;
    		day = checkDay( theDay );
    
    		System.out.printf(
    			"Date object constructor for date %s\n", this );
    		}
    
    		private int checkMonth( int testMonth )
    		{
    			if ( testMonth > 0 && testMonth <= 12 )
    				return testMonth;
    			else
    			{
    				System.out.printf(
    					"Invalid month (%d) set to 1.", testMonth );
    				return 1;
    			}
    		}
    
    		private int checkDay( int testDay )
    		{
    			int daysPerMonth[] =
    				{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
    			if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
    				return testDay;
    
    			if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
    					( year % 4 == 0 && year % 100 != 0 ) ) )
    				return testDay;
    
    			System.out.printf( "Invalid day (%d) set to 1.", testDay );
    			return 1;
    		}
    
    		public String toString()
    		{
    			return String.format( "%d/%d/%d", month, day, year );
    		}
    
    		public static void main(String args[]){
    			//we pass month,date,year as argument
    			Date dt=new Date(12,12,2009);
    			System.out.println(dt.toString());
    		}
    	}

  5. #5
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    sorry but it's not what i wanted to be executed ! take a look at following ...

    " Calendar Display
    John would like a system that will display the monthly calendar of his choice. He will provide the month and year, system will display a well formatted monthly calendar based on these input.
    "
    can u help me please ?

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    sorry but it's not what i wanted to be executed !
    This is not a "CODE-R-US" forum and apparently, this is not your code either (because you don't have a clue what it does). The code you posted will not give you the output you're looking for. You probably will have to use the the Calender class.

    Calendar (Java Platform SE 6)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    pinkdreammsss is offline Member
    Join Date
    Apr 2009
    Posts
    84
    Rep Power
    0

    Default

    First , what do u mean of " code r us " ?! u mean i cann't ask for some simple java codes as i'm a beginner ?
    second , the code definitely is not mine , i got it from a book but the result isn't what exactly i'm looking for ! actually this is my assignment and i've got to get it done.
    thanks for your help and i hope someone help me on this ...

  8. #8
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Its all the same, the only additional thing what you need is the user input

    Java Code:
    import java.util.*;
    public class Date
    {
    	private int month;
    	private int day;
    	private int year;
    
    	public Date( int theMonth, int theDay, int theYear )
    	{
    		month = checkMonth( theMonth );
    		year = theYear;
    		day = checkDay( theDay );
    
    		System.out.printf(
    			"Date object constructor for date %s\n", this );
    		}
    
    		private int checkMonth( int testMonth )
    		{
    			if ( testMonth > 0 && testMonth <= 12 )
    				return testMonth;
    			else
    			{
    				System.out.printf(
    					"Invalid month (%d) set to 1.", testMonth );
    				return 1;
    			}
    		}
    
    		private int checkDay( int testDay )
    		{
    			int daysPerMonth[] =
    				{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
    			if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
    				return testDay;
    
    			if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
    					( year % 4 == 0 && year % 100 != 0 ) ) )
    				return testDay;
    
    			System.out.printf( "Invalid day (%d) set to 1.", testDay );
    			return 1;
    		}
    
    		public String toString()
    		{
    			return String.format( "%d/%d/%d", month, day, year );
    		}
    
    		public static void main(String args[]){
    			//we pass month,date,year as argument
    			Scanner sc=new Scanner(System.in);
    			System.out.print("Please enter month::");
    			int mon=sc.nextInt();
    			System.out.print("Please enter date::");
    			int dd=sc.nextInt();
    			System.out.print("Please enter year::");
    			int yy=sc.nextInt();
    			Date dt=new Date(mon,dd,yy);
    			System.out.println(dt.toString());
    		}
    	}

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    The comment about "CODE-R-US" is meant to mean that this isn't "code for hire for free" forum. The idea is to help people understand and learn Java.... not to give them complete working code which they can to turn in for assignments. If you have a specific question, you will get a specific answer.
    From what you have stated and shown, you need to go back to the basics.

    Java tutorial:
    The Java™ Tutorials

    ... or you can also do a google for "java calendar display month"

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. How to add a calendar????
    By zifis in forum New To Java
    Replies: 5
    Last Post: 04-07-2009, 04:04 PM
  2. Calendar bug?
    By Stigvig in forum Advanced Java
    Replies: 14
    Last Post: 02-08-2009, 09:56 AM
  3. Calendar language problem
    By kopros in forum New To Java
    Replies: 1
    Last Post: 10-27-2008, 10:00 PM
  4. calendar
    By John in forum SWT / JFace
    Replies: 12
    Last Post: 08-07-2008, 10:54 PM
  5. Problem with calendar
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •