• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Range checking on Say 4a

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on the Java 4a (Say) assignment. Perhaps someone can shed some light on a my question.
Is it safe to assume that the person will enter a number of some form or should we check for that?
Thanks!
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to make sure the number is in the proper range but you don't need to make sure it is a number.
Bill
 
Elisabeth Van
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Now if I'm not mistaken, we need to check to see that the number is between 0 and 99. However, at the same time I checked to see that a single argument was passed, I also checked to see that the argument had a length <= 2, which I believe accomplishes the same thing as checking to see if the value is between 0 and 99.
I prefaced that line of code stating that I was checking to see that there was only one argument and that it had 2 or fewer digits.
So why am I getting the comment "Where is the range checking?"
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Write a program that will read in a number from 0 to 99 and spell out that number. The program must also report any values that are out of range."
You need to print a message to the user if the value is out of range.
[This message has been edited by Marilyn deQueiroz (edited February 28, 2001).]
 
Elisabeth Van
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I guess that means that a different type of error message other than the usage error has to be given.
Thanks for the clarification.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checking to see if the length of the argument is less than 2 doesn't really do the samething as check to see if it is 99 or less because I can type in "ab" and it will pass your range check. I know I said you don't have to make sure they entered a number, but you do need to make sure your range checking doesn't pass unless it is a valid response.
I am probably confusing you some, but I don't want to give you the solution without making you think about it.
Bill
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Also negative single digit numbers like "-1" also have a length of two but it is not in the required range ...
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic