Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ISBNVerifier (JAVA) Background description: An International Standard Book Number (ISBN) is a code that uniquely identifies an edition of a book. The ISBN consists of

ISBNVerifier (JAVA)

Background description:

An International Standard Book Number (ISBN) is a code that uniquely identifies an edition of a book. The ISBN consists of ten digits separated by dashes into groups. The groups are of various sizes, except for the last group. The last group is always a single character, '0' through '9' or 'X', and acts as a check on the rest of the digits. In this problem we look at 10 digit ISBNs

0-670-03441-X

0-201-48558-3

1-56592-262-X

0-06-027900-1

0-439-45695-9

0-470-84371-3

1-4000-3136-2

0-19-856453-8

1-85671-104-8

The last character is calculated from the other 9 digits:

Key Algorithm to calculate check digit.

Multiply the first digit by 10.

Multiply the second digit by 9.

Multiply the second digit by 8.

. . .

Multiply the ninth digit by 2.

Add up all these values.

Integer divide the sum by 11.

Find the remainder.

Subtract the remainder from 11. This is the check digit.

If the checkDigit is 10, use an 'X'

For example:

0-201-48558-3

0 * 10 = 0

2 * 9 = 18

0 * 8 = 0

1 * 7 = 7

4 * 6 = 24

8 * 5 = 40

5 * 4 = 20

5 * 3 = 15

8 * 2 = 16

-----

sum = 140

140 / 11 = 12 rem 8

11 - 8 = 3 <-- the check digit

Write a program that prompts the user for a file containing ISBN numbers and then checks if each the ISBN is correct. I have posted the isbnCodes.txt file in the Program Projects Answers/Project 2 tab on the web site and you may use it to test your results

Here is a complete description of what I want you to do:

In main:

Create a Scanner to read in the name of the input file as a String.

Call a method createScanner with the parameter of the String file. createScanner should return a reference to a scanner that allows you to read from the input file.

For each ISBN code in the file

Read in the potential ISBN codes one at a time as a StringBuilder.

Call checkISBN with the reference to StringBuilder object you have read in. checkISBN returns a String reference with a message telling whether this is a valid code, and if not why not.

Print the message to the screen , along with the ISBN number entered. (see sample output when using the file I have provided).

Close the Scanner used to read he file.

In createScanner:

Accept the reference to the file name as a String.

Create a Scanner object that reads from that file. Be sure to check for the files existence.

Return a reference to the created Scanner

In checkISBN:

Perform the following checks. If a check leads to an error, return a message listing the error. Below is my suggested order.

Here are steps you may follow:

Check that total length is 13.

Make sure the 12th position is a digit or X

Make sure that there are exactly three - in the code.

Check to make sure that each character except the last is a digit or a dash.

Extract the nine digits in order

Calculate the check digit.

If the check digit matches as described above return a message indicating a good ISBN, otherwise return a message indicating that a bad ISBN was created because the digit doesnt match

Helpful Hint:

Here is an example of how to convert the char to an int:

char x = '9';

int y = x - '0'; // gives 9 remember the subtraction will cast up to int and the int characters are sequential in UNICODE.

Sample output:

Please enter a the file name containing the ISBN Files: isbnCodes.txt

A check on the ISBN 0-670-03441-X yields: Good - final digit is X

A check on the ISBN 0-201-48558-3 yields: Good Digits Match

A check on the ISBN 1-56592-262-X yields: Good - final digit is X

A check on the ISBN 0-06-027900-1 yields: Good Digits Match

A check on the ISBN 0-439-45695-9 yields: Good Digits Match

A check on the ISBN 0-470-84371-3 yields: Good Digits Match

A check on the ISBN 1-4000-3136-2 yields: Good Digits Match

A check on the ISBN 0-19-856453-8 yields: Good Digits Match

A check on the ISBN 1-85671-104-8 yields: Good Digits Match

A check on the ISBN 92-9395 yields: Bad Length

A check on the ISBN 42-4920-223-Y yields: Final Character is Bad

A check on the ISBN 1-8906-456789 yields: There are not 3 dashes as required

A check on the ISBN 1-856X1-104-8 yields: Character not a digit or -

A check on the ISBN 1-4000-3136-5 yields: Final digit doesn't match check digit or X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions