So, in one method in this program I am writing, I have to:
1. return false if the length of the number is not 10 or 13
2. call on the isValid10Digit method for a 10 digit ISBN. isValid10Digit (boolean method) checks that the 10 digit code has a valid check number, and this code is already written.
3. call on the isValid13Digit method for a 13 digit ISBN. Same idea here.
Yet, I can't seem to do these all in one isValid method. What I have right now is it taking a string parameter so that it can take dashes. I then remove the dashes so that you have a string that is really just numbers. I tried putting in:
return (c.length() == 10 || c.length() == 13);
And then I don't know how to "call" on the other two methods now. What does that even mean? What do I do?
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
well, what you could do is..
boolean toReturn = (c.length() == 10 || c.length() == 13);
if (isValid10Digit())
do whatever
if (isValid13Digit())
do whatever
return toReturn;
-This is what your going for. The method can only have 1 return inside of it, and if anything is after the return (except for comments) will cause an error. what you want to do, is you can just store what you want to return at the beginnning, and then call the 2 methods, and after they've been called, return false if not 10, or 13.
You *can* call return more than once in the same method if the return statements are within if-statements.
Here's how it could be done:
http://ideone.com/u0mkNU