Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Date accessor method error

 
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:

 
Marshal
Posts: 25823
69
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?
 
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

???
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic