This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Validation Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Validation Problem" Watch "Validation Problem" New topic
Author

Validation Problem

Darren Wilkinson
Greenhorn

Joined: Feb 09, 2004
Posts: 21
Hello

I need help on how to approach the solution to the problem, rather than actual code.

In my assignment I have a class called VehicleRecord which has two fields: String registrationDate and String expiryDate.

This class must include validation methods (for validating the data supplied by the user for the fields) and I have to use the following method signature; .

The above validation method has to be used for validating two different dates, registrationDate and expiryDate (both with the same validation parameters : 4 digits (MMDD) date range = 0181 -> 1220) after the user has supplied them but [ITALIC]before[/ITALIC] the supplied data is passed to the respective field.

I have coded the actual validation and it works fine.

The problem I have is that the method signature does not allow for any returned value. Due to this, I do not see a way that the validation method can tell which date it is validating, so the following cannot happen...



... because which fields date is the method validating.

I am restricted by the terms of the assignment but if I were not, I would go about it as follows (in fact I have and this approach works fine).



... but I cant use the above approach.

Can anyone suggest a way to approach this problem?

Thank you
[ July 22, 2004: Message edited by: Darren Wilkinson ]
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
why dont you use



and then change it in your validation method according to wheter valid or invalid, and then you can check for its state from your setter.




or do I miss here something?
[ July 22, 2004: Message edited by: Ben Buchli ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Something to play around with - but I don't understand "date range = 0181 -> 1220"
so I've just built in < 181 or > 1220 is invalid

 
wood burning stoves
 
subject: Validation Problem