• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date accessor method error

 
Josiah smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems with the accessor method at for the generateRandomDate. The method should return a date in MM/DD/YEAR.
//return new Date(month, day, year); But instead I get a long date? This is causing problems using a dateComparator to sort the queue. Can someone identify what I am missing???



The date comprator that I am using is:

 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's your code:


Here's the signature of the constructor you chose, directly from the API documentation:


Do you see your problem?

And by the way your DateComparator has far too much code in it. Date already implements Comparable<Date> so all you need is to use that, along with a bit of generics to get rid of the casts:
 
Josiah smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am at work and don't have jdk ability right now, but if i used

Will that solve my problem?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josiah smith wrote:I am at work and don't have jdk ability right now, but if i used

Will that solve my problem?


No.

Look more closely at Paul's post. In particular, look closely at the differences he's pointing out between what the Date constructor expects and what you're passing.

Look very closely. Piece by piece. It's blatantly obvious, if you pay attention.
 
Josiah smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh. I think I found it. Should be

???
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josiah smith wrote:Ahh. I think I found it. Should be???

Look again. Hint: The United States is, as far as I know, the only country on the planet to use that insane form of date.

Winston
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josiah smith wrote:Ahh. I think I found it. Should be

???


Isn't that what you already have?

Look again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic