Results 1 to 9 of 9
Thread: Calendar - problem in Cprompt
- 04-14-2009, 10:39 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 84
- Rep Power
- 0
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 ); } }
- 04-14-2009, 10:49 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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){
}
- 04-14-2009, 10:53 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 84
- Rep Power
- 0
so , can you rewrite this code please ?
- 04-14-2009, 11:10 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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()); } }
- 04-14-2009, 12:10 PM #5
Member
- Join Date
- Apr 2009
- Posts
- 84
- Rep Power
- 0
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 ?
- 04-14-2009, 12:43 PM #6
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.sorry but it's not what i wanted to be executed !
Calendar (Java Platform SE 6)
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 04-14-2009, 12:52 PM #7
Member
- Join Date
- Apr 2009
- Posts
- 84
- Rep Power
- 0
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 ...
- 04-14-2009, 01:04 PM #8
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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()); } }
- 04-14-2009, 01:09 PM #9
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
How to add a calendar????
By zifis in forum New To JavaReplies: 5Last Post: 04-07-2009, 04:04 PM -
Calendar bug?
By Stigvig in forum Advanced JavaReplies: 14Last Post: 02-08-2009, 09:56 AM -
Calendar language problem
By kopros in forum New To JavaReplies: 1Last Post: 10-27-2008, 10:00 PM -
calendar
By John in forum SWT / JFaceReplies: 12Last Post: 08-07-2008, 10:54 PM -
Problem with calendar
By Felissa in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks