Reputation: 415
So I'm still plugging away at my big assignment (thanks to everyone for helping me figure out the problem with my loop). Now i have moved on to start making a checkDigit() method that is used to validate whether the check digit on the isbn # is valid (which I have only started screwing around with). Here's the problem: I tried to compile it, but the compiler tells me that there is an expected at the method call. Here is a snippet of my beginner's code:
private String validateISBN(String bookNum)throws ISBNException
{
boolean check=false;
bookNum.replaceAll("-","");
if (bookNum.length()!=ISBN_NUM)
throw new ISBNException ("ISBN "+ bookNum + " must be 10 characters");
for (int i=0;i<bookNum.length()-1;i++)
{
if (Character.isDigit(bookNum.charAt(i)))
check=true;
}
if (bookNum.charAt(9)=='X') check=true;
if (Character.isDigit(bookNum.charAt(9))) check=true;
if (check=false) throw new ISBNException ("ISBN " + bookNum + " must contain all digits" +
"or 'X' in the last position");
if (checkDigit()=false)
throw new ISBNException ("ISBN " + bookNum + " is invalid.\n" +
"ISBN " + bookNum + " should be " + validnum);
if (check=true) return bookNum;
}
public boolean checkDigit (bookNum)
{
double total=0.0;
char[] check = {1,2,3,4,5,6,7,8,9,X};
int[] checkNums= {1,2,3,4,5,6,7,8,9,10};
for (int i=0;i<bookNum.length;i++)
check(i)=bookNum[i];
total+=check[i]*checkNums[i];
What exactly does this mean? Normally it only means that I am missing a curly brace somewhere, but that is not the case this time.
edit
Sorry for the obvious and stupid question. For you guys who asked to see the actual compiler message, I put it up top (buried), it was that the compiler
identifier expected
but I actually put the <> tags around identifier, so it took out the word identifier, and now it says, "....but the compiler tells me that there is an expected at the method call, instead of, " ....but the compiler tells me that there is an identifier expected at the method call.
And the enter that was originally at the start was from the text field (which I am typing the question) for when I pasted the code, it said 'enter code here', and I didn't take out the enter.
Sorry
Upvotes: 0
Views: 161
Reputation: 9249
Well it appears you are in fact missing the closing curly brace for your checkDigit
method, plus what is that stray enter
doing before the validateISBN
method? Also, you need to type the bookNum
parameter to your checkDigit
method, i.e., checkDigit(String bookNum)
And lastly, you're attempting to call checkDigit()
without passing in any arguments here:
if (checkDigit()=false)
throw new ISBNException ("ISBN " + bookNum + " is invalid.\n" +
"ISBN " + bookNum + " should be " + validnum);
You need to provide bookNum
in this method call.
Furthermore, it is an excellent idea to post the compiler message along with your question; someone's almost immediately going to ask you for it, so just do it. Plus, if you take a minute to read the compiler message, it's usually pretty obvious what the problem, at least for something as simple as incorrect syntax.
Upvotes: 3
Reputation: 11
Does it fix the problem if you put 'X' in single quotes for the check array?
Upvotes: 1
Reputation: 8642
At first glance it looks like you have a stray enter
before the method signature for validateISBN
and you also are missing a type declaration for the bookNum
argument to the checkDigit
method.
Upvotes: 1