@Test void testConvert13to10() { Book b; b = new Book("9780306406157", "", ""); assertEquals("0306406152", b.convertToIsbn10()); b = new Book("9780596007126", "", ""); assertEquals("0596007124", b.convertToIsbn10()); b = new Book("9781491950357", "", ""); assertEquals("1491950358", b.convertToIsbn10()); }
public String convertToIsbn10() { if(isbn.length() == 10) { return isbn; } String newIsbn = isbn.substring(3, 12); int total = 0; int multiplier = 10; for(int i = 0; i < newIsbn.length(); i++) { int digit = newIsbn.charAt(i) - '0'; total += digit * multiplier; --multiplier; } int checkDigit = (11 - (total % 11)) % 11; newIsbn += String.valueOf(checkDigit); return newIsbn; }
Book { public String convertToIsbn10() { if(isbn.length() == 10) { return isbn; } String newIsbn = isbn.substring(3, 12); int total = 0; int multiplier = 10; for(int i = 0; i < newIsbn.length(); i++) { int digit = newIsbn.charAt(i) - '0'; total += digit * multiplier; --multiplier; } int checkDigit = (11 - (total % 11)) % 11; newIsbn += String.valueOf(checkDigit); return newIsbn; } }
Book { public String convertToIsbn10() { if(isbn.length() == 10) { return isbn; } String newIsbn = isbn.substring(3, 12); int total = 0; int multiplier = 10; for(int i = 0; i < newIsbn.length(); i++) { int digit = newIsbn.charAt(i) - '0'; total += digit * multiplier; --multiplier; } int checkDigit = (11 - (total % 11)) % 11; newIsbn += String.valueOf(checkDigit); return newIsbn; } Book(String isbn, String author, String name); }
Book { public String convertToIsbn10() { if(isbn.length() == 10) { return isbn; } String newIsbn = isbn.substring(3, 12); int total = 0; int multiplier = 10; for(int i = 0; i < newIsbn.length(); i++) { int digit = newIsbn.charAt(i) - '0'; total += digit * multiplier; --multiplier; } int checkDigit = (11 - (total % 11)) % 11; newIsbn += String.valueOf(checkDigit); return newIsbn; } Book(String isbn, String author, String name); String convertToIsbn13(); String convertToIsbn10(); }
Book { public String convertToIsbn10() { if(isbn.length() == 10) { return isbn; } String newIsbn = isbn.substring(3, 12); int total = 0; int multiplier = 10; for(int i = 0; i < newIsbn.length(); i++) { int digit = newIsbn.charAt(i) - '0'; total += digit * multiplier; --multiplier; } int checkDigit = (11 - (total % 11)) % 11; newIsbn += String.valueOf(checkDigit); return newIsbn; } Book(String isbn, String author, String name); String convertToIsbn13(); String convertToIsbn10();  }