NeXuS1
Fully Optimized
- Messages
- 2,960
Here are the instructions, I have some code but having trouble converting and doing the multiplication.
Project 4: ISBN Evaluator and test harness.
An International Standard Book Number (ISBN) is a code of 10 characters separated by dashes such as
0-8065-0959-7. An ISBN consists of four parts:
• a group code,
• a publisher code,
• a code that uniquely identifies the book among those published by the particular publisher, and
• a check character
For the ISBN 0-8065-0959-7, the group code is 0, which identifies the book as one from an Englishspeaking
country. The publisher code 8065 identifies the book as one published by Citadel Press. The
code 0959 uniquely identifies the book among those published by Citadel Press (Brode: Woody Allen:
His Films and Career, in this case).
The check character is computed as follows:
First, compute the sum of the first digit plus two times the second digit plus three times the third
digit, ... , plus nine times the ninth digit. The last character is the remainder when the sum is divided by
11. If the remainder is 10, the last character is X. For example, the sum for the ISBN 0-8065-0959-7 is
0 + 2*8 + 3*0 + 4*6 + 5*5 + 6*0 + 7*9 + 8*5 + 9*9 = 249
The remainder when 249 is divided by 11 is 7, the last character in the ISBN. The check character is
used to validate an ISBN.
Write a class that has a method that accepts an array of characters, consisting of both numbers and
hyphens. The function returns true if the array represents a valid ISBN and false otherwise.
For full credit, you must also provide an adequate test harness to test your class with multiple ISBNs.
Here are a few you might consider using:
"0-8065-0959-7",
"0-534-37964-8",
"0-618-50298-X",
"0-8065-0959-8", //bad
"0-534-37964-9", //bad
"0-618-50298-5", //bad
"0-534-37964-8",
"0-618-50298-X",
"032121353X",
"0321199553",
"0201794896",
"0870495275",
"0452264464",
For additional information on ISBN's, see http://en.wikipedia.org/wiki/ISBN.
import java.util.StringTokenizer;
public class ISBN1
{
public static void main(String[] args)
{
String ISBN = "0-8065-0959-7";
boolean valid = false;
StringTokenizer strTokenizer = new StringTokenizer(ISBN, "-");
String part1 = strTokenizer.nextToken();
String part2 = strTokenizer.nextToken();
String part3 = strTokenizer.nextToken();
String part4 = strTokenizer.nextToken();
}
}
I got them separated but I am having trouble allocating them then converting then into integers.
Project 4: ISBN Evaluator and test harness.
An International Standard Book Number (ISBN) is a code of 10 characters separated by dashes such as
0-8065-0959-7. An ISBN consists of four parts:
• a group code,
• a publisher code,
• a code that uniquely identifies the book among those published by the particular publisher, and
• a check character
For the ISBN 0-8065-0959-7, the group code is 0, which identifies the book as one from an Englishspeaking
country. The publisher code 8065 identifies the book as one published by Citadel Press. The
code 0959 uniquely identifies the book among those published by Citadel Press (Brode: Woody Allen:
His Films and Career, in this case).
The check character is computed as follows:
First, compute the sum of the first digit plus two times the second digit plus three times the third
digit, ... , plus nine times the ninth digit. The last character is the remainder when the sum is divided by
11. If the remainder is 10, the last character is X. For example, the sum for the ISBN 0-8065-0959-7 is
0 + 2*8 + 3*0 + 4*6 + 5*5 + 6*0 + 7*9 + 8*5 + 9*9 = 249
The remainder when 249 is divided by 11 is 7, the last character in the ISBN. The check character is
used to validate an ISBN.
Write a class that has a method that accepts an array of characters, consisting of both numbers and
hyphens. The function returns true if the array represents a valid ISBN and false otherwise.
For full credit, you must also provide an adequate test harness to test your class with multiple ISBNs.
Here are a few you might consider using:
"0-8065-0959-7",
"0-534-37964-8",
"0-618-50298-X",
"0-8065-0959-8", //bad
"0-534-37964-9", //bad
"0-618-50298-5", //bad
"0-534-37964-8",
"0-618-50298-X",
"032121353X",
"0321199553",
"0201794896",
"0870495275",
"0452264464",
For additional information on ISBN's, see http://en.wikipedia.org/wiki/ISBN.
import java.util.StringTokenizer;
public class ISBN1
{
public static void main(String[] args)
{
String ISBN = "0-8065-0959-7";
boolean valid = false;
StringTokenizer strTokenizer = new StringTokenizer(ISBN, "-");
String part1 = strTokenizer.nextToken();
String part2 = strTokenizer.nextToken();
String part3 = strTokenizer.nextToken();
String part4 = strTokenizer.nextToken();
}
}
I got them separated but I am having trouble allocating them then converting then into integers.