package models;

import org.apache.commons.validator.routines.ISBNValidator;

/** 
 * A textbook object that represents a textbook.
 * @author Alvin Wang, Eduard Gamiao
 *
 */
public class Textbook {  
  private String title;
  private String author;
  private String isbn;
  private String condition;
  private String textbookURL;
  
  /**
   * Constructor for a textbook.
   * @param title The textbook title.
   * @param author The textbook author.
   * @param isbn The textbook isbn.
   * @param condition The textbook condition.
   */
  public Textbook(String title, String author, String isbn, String condition) {
    this.title = title;
    this.author = author;
    this.isbn = isbn;
    this.condition = condition;
    this.textbookURL = createURL(this.isbn);
  }

  /**
   * @return the title
   */
  public String getTitle() {
    return title;
  }

  /**
   * @param title the title to set
   */
  public void setTitle(String title) {
    this.title = title;
  }

  /**
   * @return the author
   */
  public String getAuthor() {
    return author;
  }

  /**
   * @param author the author to set
   */
  public void setAuthor(String author) {
    this.author = author;
  }

  /**
   * @return the isbn
   */
  public String getIsbn() {
    return isbn;
  }

  /**
   * @param isbn the isbn to set
   */
  public void setIsbn(String isbn) {
    this.isbn = isbn;
  }

  /**
   * @return the condition
   */
  public String getCondition() {
    return condition;
  }

  /**
   * @param condition the condition to set
   */
  public void setCondition(String condition) {
    this.condition = condition;
  }

  /**
   * @return the textbookURL
   */
  public String getTextbookURL() {
    return textbookURL;
  }

  /**
   * @param textbookURL the textbookURL to set
   */
  public void setTextbookURL(String textbookURL) {
    this.textbookURL = textbookURL;
  }
  
  /**
   * Generate a URL that links to the book image.
   * @param productCode The ISBN of the book.
   * @return A URL of the image for the book.
   */
  public static String createURL(String productCode) {
    ISBNValidator validator = new ISBNValidator(true);
    return validator.toString();
  }
  
  /**
   * Convert an ISBN13 to ISBN10.
   * @param isbn13 The ISBN to be converted.
   * @return A ISBN10 representation of the ISBN13.
   */
  public static String convertISBN13To10(String isbn13) {
    return "";
    
  }
  
}

@@ -195,16 +195,137 @@
 ook %7B  %0A
+  private static final Integer THREE = 3; // For CheckStyle.%0A  private static final Integer TEN = 10; // For CheckStyle.%0A
   privat
@@ -2207,89 +2207,44 @@
     
-ISBNValidator validator = new ISBNValidator(true);%0A    return validator.toString(
+return convertISBN13To10(productCode
 );%0A 
@@ -2458,23 +2458,894 @@
     
-return %22%22;%0A    
+if (new ISBNValidator().isValidISBN13(isbn13)) %7B%0A      // Multiply the first 12 digits of the ISBN by 1 or 3 based on position.%0A      Integer sum = 0;%0A      Integer multiplier = 1;%0A      char %5B%5D digitArray = isbn13.toCharArray();%0A      for (char c : digitArray) %7B%0A        if (multiplier == 1) %7B%0A          sum += Character.getNumericValue(c) * multiplier;%0A          multiplier = THREE;        %0A        %7D%0A        else if (multiplier == THREE) %7B%0A          System.out.println(c + %22 * %22 + multiplier);%0A          sum += Character.getNumericValue(c) * multiplier;%0A          multiplier = 1;%0A        %7D%0A      %7D%0A      %0A      String sumString = %22%22 + sum;%0A      %0A      return (sum %25 TEN == 0) ? isbn13.substring(3, isbn13.length() - 1).concat(%220%22) %0A             : isbn13.substring(3, isbn13.length() - 1).concat(%22%22 + sumString.charAt(sumString.length()));%0A    %7D%0A    else %7B%0A      return isbn13;%0A    %7D
 %0A  %7D

ISBN conversion pt. 1