Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation Problem

 
Darren Wilkinson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic