• Post Reply Bookmark Topic Watch Topic
  • New Topic

Improvement suggestion on handling nulls, negative values etc.  RSS feed

 
sam lenk
Greenhorn
Posts: 3
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have written two methods. Just not sure where and how to best handle possible errors (negative values, ceros, etc.)

The two methods are intended to convert decimal number into hours of format HH:mm:ss and vice versa.

Please post suggestions! Thanks in advance! SL


 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried calling the methods with a selection of arguments (eg for dec2Hours() try NaN, negative number, 0, max Double etc) to see what happens?
If the parameter's value is illegal you can take appropriate action such as throwing an Exception.
 
sam lenk
Greenhorn
Posts: 3
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Tony.

Thanks for your reply!

I kind of did that. I will complete with things such as NaN, null, etc.

Another question: in general do you recommend writing the test/-s frist and later putting methods together? I just wonder because I remember having read this somewhere.

Thanks again!

Sam
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another question: in general do you recommend writing the test/-s frist and later putting methods together? I just wonder because I remember having read this somewhere.

It's a good habit to get into.
Do I always do this? No.
Do I sometimes regret not doing it? Yes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!