aspose file tools*
The moose likes Beginning Java and the fly likes toSrting() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toSrting() method" Watch "toSrting() method" New topic
Author

toSrting() method

Gordan Lee
Greenhorn

Joined: Oct 02, 2003
Posts: 6
i have a class month, day and year
my toSring() is
public String toString()
{
String report;
report = "+ month / + day / + year";
//report = report + "+ day";
//report = report + "+ year";
return report;
}
i take out the 2 lines of // because the assignment asks me to do
toString(): String [in the format of mm/dd/yyyy
is my toString method correct? thanks.
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
It doesn't appear to do what you want. You said you have a class month day year, but since you have spaces I assume that means you have either 3 variables in a class or 3 classes with those names. I'll assume the first case.
If your class were something such as -

This should get you started. HTH.
Regards, Aaron R>
[ October 27, 2003: Message edited by: Aaron Roberts ]
Gordan Lee
Greenhorn

Joined: Oct 02, 2003
Posts: 6
Here is my code: (it compiles fine and runs but i need to know if i am doing the assignment correctly. thanks)
public class Date
{
private int day;
private int month;
private int year;

public Date()
{

day = 0;
month =0;
year = 0;
}

public Date(int day, int month, int year)

{
this.day = day;
this.month = month;
this.year = year;
}

public int getMonth()
{
return month;
}

public int getDay()
{
return day;
}

public int getYear()
{
return year;
}


public void setMonth(int month)
{
this.month = month;
}

public void setDay(int day)
{
this.day = day;
}

public void setYear(int year)
{
this.year = year;
}


public String toString()
{
String report;
report = "+ month / + day / + year";
//report = report + "+ day";
//report = report + "+ year";
return report;
}

public boolean equals(Date anotherDate)

{
boolean isEqual;
isEqual = ((day == anotherDate.getDay()) &&
(month == anotherDate.getMonth()) &&
(year == anotherDate.getYear()));


return isEqual;


}

}
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I can't answer if you are doing the assignment correctly, as I don't know what the assignment is. If your assignment tells you exactly what your class should do and your class does that, everything must be right. Did you check to see if the toString method outputs the date in the format you wanted? When I was in school, I was scored based on how good my comments were, whether the routines actually worked, etc.
Regards,
Aaron R>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toSrting() method