Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date format reversing

 
JeffreyAaron Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on a pair of programs (driver and driven) that will accept input in the form of numbers a slash mark and numbers, which represent the month and day. The program error checks the input for valid numbers and then prints a line with the numbers as entered (mm/dd) and with the month spelled out (Month dd). Unfortunately, my code is somehow reversing the value for the date (i.e. 02/05=May 2).

I'm sure this is something simple I'm overlooking, but I've been scouring this code all day and can't find it. Any help would be greatly appreciated.

The driver:


And the driven class:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, it's not the best idea to name your own classes the same as Java classes. Leave "Date" alone.

And, why are you writing all this code when the DateFormat and Calendar classes already have it all solved for you?
 
JeffreyAaron Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because this is a project for a class with very specific requirements. For instance the driven class portion of the program must be named, "Date.java" and the driver named "LastnameFirstnameDateDriver.java". It also must include a Date constructor that receives a string called dateStr. It must error check the input using try/catch.

Unfortunately now I've been error checking, rewriting, adding, deleting for so long now, I'm not sure where I'm at...looking over the code, I suspect I have complicated it more than it needs to be.

I'm sorry to be asking, but can you help look through my code and streamline/debug?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You expect the input format to be mm/dd - but this is not what you expect in your Date code.

You start with finding the date delimiter '/', then you try to find the month, but is is the day you select (spot + 2) - and then you try to find the day, but also here you select the wrong one, you select the month (spot -1)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic