I have a question about a program I am writing.
Background: I am a new Java student, and have just been introduced to object oriented programing.
I have two files (Date.java and DateTest.java) one containing the class Date and one containing class DateTest and the main function.
I believe this to be as simple of a question as there could be in this type of programing but i am having problems getting results from my code.(thank you for taking the time to help)
I have get and set methods and a constructor for the variables Day, Month and Year; I also have a display method.
I believe the problem is in my display method? When I compile and run the program this method doesn't seem to do anything at all, when to the extent of my knowledge it should be displaying the date in the output.
I have been trying to find some kind of clue as to what is wrong in my book, but nothing seems to be working.
I have a strange feeling that it has to do with some sort of inconsistency between my two files, but I don't see it.
So, here is my code.
Date.java
public class Date
{
private int dateDay;
private int dateMonth;
private int dateYear;
public Date( int day, int month, int year )
{
dateDay = day;
dateMonth = month;
dateYear = year;
}
public void setDateDay( int day )
{
dateDay = day;
}
public int getDateDay()
{
return dateDay;
}
public void setDateMonth( int month )
{
dateDay = month;
}
public int getDateMonth()
{
return dateMonth;
}
public void setDateYear( int year )
{
dateDay = year;
}
public int getDateYear()
{
return dateYear;
}
public void displayDate()
{
System.out.printf( "", getDateMonth(), "/", getDateDay(), "/", getDateYear(), "\n" );
}
}
DateTest.java
public class DateTest
{
public static void main( String agrgs[] )
{
Date date1 = new Date( 7, 4, 2004 );
System.out.printf( "The initial date is: " );
date1.displayDate();
date1.setDateMonth( 11 );
date1.setDateDay( 1 );
date1.setDateYear( 2003 );
System.out.printf( "Date with new values is: " );
date1.displayDate();
System.out.println();
}
}
Thanks for the help, this is my first time posting!

New Topic/Question
Reply



MultiQuote


|