Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Darrin
Date Java
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners


I'm using the eclipse software and I get an error for my porgramming for the Date.java..Please assist.Here's what I have so far:



public class Date {
private int month; // 1-12
private int day; // 1-31 based on month
private int year; // any year

// constructor: confirm proper value for month;
// call method function checkDay to confirm proper value for day.
public Date( int theMonth, int theDay, int theYear ) {
if ( theMonth > 0 && theMonth <= 12 ) // validate month
month = theMonth;
else {
month = 1;
System.out.println( "Month " + theMonth +
" invalid. Set to month 1." );
}
year = theYear;
day = checkDay ( theDay ); // validate day
System.out.println("Date object constructor for date "+ toString() );
}

// utility method to confirm proper day value based on month and year.
public 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;
System.out.println( "Day " + testDay + " invalid. Set to day 1." );
return 1; // leave object in consistent state
}
// increment the day and check if doing so will change the month
public void nextDay() {
// implement the nextDay method here!!!!
}

// create a String of the form month/day/year
public String toString() {
return month + "/" + day + "/" + year;
}

} // end class Date


public class DateTest {
public static void main( String args[] ){
System.out.println( "Checking increment" );
Date testDate = new Date( 11, 27, 1988 );
// test incrementing of day, month and year
for ( int counter = 0; counter < 40; counter++ ) {
testDate.nextDay();
System.out.println( "Incremented Date:" + testDate.toString() );
}
}
}


Advertisement
View Answers

January 28, 2010 at 3:04 PM


Hi Friend,

You have declared both the classes 'public' therefore you have got the error.Save your java class as DateTest.java and remove the 'public' modifier from the Date.java class.

Thanks


Related Tutorials/Questions & Answers:
Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql
Mysql Date To Java Date
Mysql Date To Java Date       Mysql Date To Java Date retrieve the records from Mysql and display the date in java. Understand with Example The Tutorial illustrate an example from
Advertisements
how to add date and change date in java - netbeans
how to add date and change date in java - netbeans  I need to code use to increase date How to get date after 30 days using netbeans
java Date - Java Beginners
java Date  Dear sir I have an assignment, It is .. "Develop Date class in java similar to the one available in java.util package.Use JavaDoc..., Try the following code: public class Date { private final int month
java - Date Calendar
Java convert string to date  I need an example in Java to convert the string to date.  Convert string to date formatimport... str_date="04-04-2008"; DateFormat formatter ; Date date
date picker - Java Beginners
date picker  sir i need code for date picker in java swing because for Embedding in my project plz sir
Display Date - Java Beginners
Display Date  Plz send me sample java program that display day, date... to display day,date,year and current time. import java.util.*; class DateExample { public static void main(String[] args) { Date date = new Date
Java Date - Java Beginners
Java Date  I have to find the previous date's beginning time and end time in the long milliseconds format. for example today date is '23rd April... main(String[] args) { Date now = new Date(); DateFormat df   Hi friend
Java programme - Date Calendar
Java programme  Can you provide me the coding for Date class provided by java util package
Date Java - Java Beginners
Date Java  I'm using the eclipse software and I get an error for my...: public class Date { private int month; // 1-12 private int day; // 1-31... for day. public Date( int theMonth, int theDay, int theYear ) { if ( theMonth
Parsing date in Java
Parsing date in Java  How can i parse the date in Java in a simple format..?   SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy
java format date
java format date  Hi, How can I format the date in the following...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date
date - Java Beginners
date  1.Write a program to check input date is valid or not using java(value must be given by user)  Hi Friend, Try the following code... DateValidation{ public boolean isValidDate(String date){ SimpleDateFormat sdf = new
java date - Java Beginners
java date   Hi, Please observe the below code: import... is "login" the name,date,time is automaticaaly inserted into the database . My doubt is iam storeing system date and system time but i want to store i server
java yesterday - Date Calendar
java yesterday  And how to make date format DD/MM/YYYY,thank's ... static void main(String args[]){ Date todaysDate = new java.util.Date... formattedDate = formatter.format(todaysDate); System.out.println("Formatted date
ask java - Date Calendar
but in java i found too but i can't to join in another frame. And i want to ask how to subtract a date, ex:i work since 2008/09/01 so i'am work until now 1 month 10... { public static void main(String[] args) { Date date = new Date
Date picker in Java Swing
Date picker in Java Swing  Hello Sir, Sir ,I am in need of Time Picker just like the Date picker available in java Swing. Kindly... link: Java Date Time Picker Example   Hello Sir, Thank
java yesterday - Date Calendar
java yesterday  Afternoon,Yesterday i have a question that how to make date sustract, the result is to make 1 month and 1 day like this, right. now how about 1 year and 1 month? And Can help me to using Date Calender what
java - Date Calendar
java   Using java how can i change the date format of the system from mm/dd/yy to dd/mm/yy. The code which i wrote is changing the format only on the console and not on the system's control panel.Can you suggest me anything
date problem - Java Beginners
date problem  how to extract day,month,year hours ,second from a string date. Examples: String dat ="200912202934" from this string extract month ,year,date,hours,minute Please help me. Thanks in advance Sushil 
Java String To Date
Java String To Date In this section you will read about how to convert... be convert into java.util.Date. Java string to date convert explains the conversion of Java string written into the specified format to a Java date object
Getting Computer Date in java
Getting Computer Date in java  Hi , I want to get the PC Date... but this.. String strDate = new Date(); I get this server error, "The type Date is ambiguous". I've also tried Date date = new Date(); ... but it get's the same error
java again - Date Calendar
java again  I can't combine your source code yesterday, can you help... : Date now : jtextfield1 //jTexfield1=date now //we enter ,then result in jTextfield2 Date work : jtextfield2 This my Source
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
Java Date
The Java Date class allows the developers to manipulate date and time from within the Java program. The Java Date class is very useful... the date with the Java Date or calendar class.   The Java Date class
date problem - Java Beginners
date problem  how to extract day,month,year hours ,second from a string date. Examples: String dat ="200912202934" from this string extract month ,year,date,hours,minute Please help me. Thanks in advance Sushil 
date format - Java Beginners
date format  how to 45day in dd-mmm-yyyy date format.  Hi...-yyyy", Locale.US); Date d = sdf.parse(timestamp); Calendar cal..."; System.out.println("Date is : " + timestampToParse); Calendar cal = parseTimestamp
date format - Java Beginners
date format  How to convert yyyy-mm-dd to dd-mmm-yyyy  Hi... void main(String args[]) throws Exception{ Date todaysDate = new java.util.Date...-dd date is ==>"+formattedDate); Date date1 = formatter.parse
Day for the given Date in Java
Day for the given Date in Java  How can i get the day for the user...("Enter date(1-31):"); int dd=input.nextInt(); System.out.println("Enter...("Enter year: "); int year=input.nextInt(); Date date= (new GregorianCalendar
Date - Java Beginners
Date  how to add 45day in dd-mmm-yyyy date format but not current... { SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.US); Date d...{ String timestampToParse = "02-Dec-2008"; System.out.println("Date
Java Date Class
Java Date Class  Hi Friend, I need to have a code to get the days between specific dates. Such if I enter 19 September 2011 to 21 September 2011, the days would be saturday, sunday and monday, the code I gave simply get one day
date picker componnt - Java Beginners
date picker componnt  sir i need code for date picker in java swing for my project sir please send me sir
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java... in Java? Thanks   Hi, Check the tutorial: Java program to get current date. Thanks   Hi, To get the current date and time in Java you can use
continue java - Date Calendar
continue java  and how to subtract date(day month year) form jframe...(); } } }); } public void getDiffer(String dt1, String dt2) throws ParseException{ Date date1;// = new Date(); Calendar calendar = Calendar.getInstance
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
continue java - Date Calendar
continue java  How to make a subtract date from jframe like jtexfield, data can input into jtextfied ? and how to get year, yesterday a have a question about how to substract dd mm yyyy can in this subtract have a year.thank
java date selector ..
java date selector ..  hey,,,, i am creating my java project...for that i implementing a car renting system and i had used combo boxes to get Ranting start day inputs..3 combo(sy,sm,sd) yyyy ,mm,dd and for returning day i need
Java Increment Date. - Java Beginners
Java Increment Date.  Create a program called Date.java to perform.... Also, provide a method nextDay() to increment the day by one. The Date object... method in a loop that prints the date during each iteration of the loop
Java Coding - Date Calendar
Java Coding  Write a program that prompts the user to enter the year and first day of the year and displays the calendar for the year on the console. For example,if the user entered the year 2005, and 6 for Saturday, January
Java Program - Date Calendar
Java Program  A java program that display calendar.  Hi Friend, Try the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.util.
Java Date Utility - Java Beginners
Java Date Utility  How to determine the maximum number of weeks in a year (52 or 53) as per the ISO Calendar? Is there any standard method in java to implement this? Or any custom method which have been used? Help needed urgently
clarify date class - Java Beginners
clarify date class  Dear, clarify this question... "Develop Date class in Java similar to the one available in java.util package. Use JavaDoc comments." Give me the source code and explain how to create classes similar
String to Date Conversion - Java Beginners
String to Date Conversion  Hi , I am retreiving time stamp of a file.... But I dont want the date/time field of access database to be changed to text. Hence I need some help for converting my String Date format to Date format, so
Java current date - How to get current date in Java
In this section, you will learn about displaying current date and time in Java
date
date   how to insert date in database? i need coding
Date Format required to change in java
Date Format required to change in java  can we change the format of date like sql as per our requirements???If yes then please give the detail solution
Java Calendar issue - Date Calendar
Java Calendar issue  Hi I have having weird situation with java Calendar, its driving me crazy. My requirenment is that i got a xml schema...:00 Is there any way to get rid of this pls help. I have tried using date
Addintion in year fields of sql date in a java page
Addintion in year fields of sql date in a java page  In my database i have a field StartDate and EndDate Now entering date from my jsp..., HttpServletResponse response) throws ServletException, IOException { Date
Advertisements
 

 

 

DMCA.com