1 Replies - 938 Views - Last Post: 18 September 2009 - 05:54 PM Rate Topic: -----

#1 dnamrax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 18-September 09

Simple Class Method Failing

Posted 18 September 2009 - 05:47 PM

Hello, thank you for reading my post.
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!

Is This A Good Question/Topic? 0
  • +

Replies To: Simple Class Method Failing

#2 dnamrax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 18-September 09

Re: Simple Class Method Failing

Posted 18 September 2009 - 05:54 PM

Sorry everyone, I should have looked around the other topics a bit more, I found the correction to my problems.

In my method "displayDate" i was using "," instead of the correct format of "+".

Thank you for reading my post and I am sorry for wasting your time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1