I am having trouble writing code that solves this problem involving check sums.

Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Since our calculation yields the same result as the final digit of the given ISBN, we conclude that this ISBN is valid.

While this may seem more complicated than UPC check digits, it can be validated very simply by adding together all the digit-by-position products (including the check digit, whose position is of course 1). If the result is a multiple of 11, then the ISBN is valid. (Recall that to check if an int n is a multiple of 11, determine whether or not n % 11 is 0.)

Question

The String Array c contains the "stringified" individual elements (including hypens) of a ten-digit ISBN. (In the above example, the contents of c would be "0", "-", "2", "0", "1", "-", "5", "3", "0", "8", "2", "-", "1", in that order.) Complete the following code to store in the boolean variable good the value true if and only if the ISBN is valid.

Ignore The Print Line I had I was trying to figure out where I was going wrong oh also the instruction provided sample test things
and the answers right here:
"1","-","2","3","4","-","5","6","7","8","9","-","X" Should come out as true
"0","-","2","0","1","-","5","3","0","8","2","-","1" good should be true again
"6","-","2","9","7","-","4","5","6","3","1","-","7" good should be false
"9","-","2","9","7","-","5","4","1","3","6","-","9" good should be false

Here's some pseudo-code for a way to implement (and debug) the beast:, building on the code that you already have:

int main(String [] args) {
// For initial debugging, why not use the ISBN from the worked example?
String[] c = {"0","-","2","0","1","-","5","3","0","8","2","-","1"};
int sum = 0;
boolean good;
// Declare other variables as needed.
// Create a loop to calculate sum
//
// In the middle of the loop you might want to print each term that is
// added into the sum. Print the value of pos and the integer value
// of the digit in that position. Then print the value of the sum.
//
//
// After the loop, use the value of the sum to calculate multipleOf11
//
//
// Print out everything that the program has been working on up to this point.
//
System.out.println("sum = " + sum + ", multipleOf11 = " + multipleOf11);
// Calculate the correct check digit.
//
int value = multipleOf11 - sum;
// Print out everything that the program will use in final calculation
//
System.out.println("value = " + value + ", c[12] = " + c[12]);
// Compare calculated check digit with the value in the ISBN
//
IF (c[12] is equal to "X") THEN
good = (value == /* Whatever it is supposed to be for 'X' */);
ELSE
good = (value == /* The integer value parsed from String c[12] */);
END IF
// Print out results
} // End of main()

Note that an 'X' can only appear as a check digit. There will never be an 'X' as any other part of the ISBN, so I don't know why the instructor seems to have something in the template to handle it???