ISBN
Complete several static methods to analyze and convert Strings representing International Standard Book Numbers (ISBNs). There are two versions of the INSB: ISBN-10 (through 2007) and ISBN-13 (after 2007). For example, the ISBNs for Harry Potter and the Prisoner of Azkaban are 0-545-58293-8 and 978-0-545-58293-3. ISBNs can include hyphens or spaces (and the rules for hyphenation are very complicated). The results from these methods ignore hyphenation, result in ISBNs with either 10 or 13 characters, and (except for convert) allow isbn parameters either with or without the check digit.
To complete the assignment, complete the following methods and click Submit:
- Complete the code for the public static char check10(String isbn) method in the Isbn class that calculates the check digit for an ISBN-10 isbn. Check digits can be any of the base-10 numerals, plus 'X' (because 11 symbols are needed when the calculation of the check digit includes
).
- Complete the code for the public static char check13(String isbn) method in the Isbn class that calculates the check digit for an ISBN-13 isbn.
- Complete the code for the public static String convert(String isbn) method in the Isbn class that converts an ISBN-10 to its corresponding ISBN-13 or an ISBN-13 to its corresponding ISBN-10. Note: only ISBN-13s that begin "978" can be converted to ISBN-10s.
The Isbn class includes additional helper methods that you can use in your solutions.
- private static String clean(String isbn, Integer ...lengths) method returns a list of isbn digits, cleaned of non-numeric and non-trailing-X characters (in an ISBN-10). Assert that the number of isbn digits is in lengths.
- public static String valid10(String isbn) method uses the check10 method to return a valid isbn, including its ISBN-10 check digit.
- public static String valid13(String isbn) method uses the check13 method to return a valid isbn, including its ISBN-13 check digit.
Include an initial comment with an @author YOUR NAME <your@email.address> line in all solution files.
Suplemental information and links
- https://en.wikipedia.org/wiki/International_Standard_Book_Number — Wikipedia entry with details on both ISBN-10 and ISBN-13.
- https://ataraxic.net/isbn-tool/ — This ISBN tool will calculate check digits (as well as hyphenation).
- https://bookow.com/resources.php — Bookow ISBN barcode generator.
- ISO 2108 — Annex C is more information than you require about the check digit for the 13 digit ISBN.
- ISBN ranges — "…up-to-date data from The International ISBN Agency regarding all Registration Group Elements, and the Registrant Element Ranges associated with them."