/home/caleb/NetBeansProjects/ADSV Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/CheckIBSN_10.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.mp2_calebfontenot;

import java.util.*;

/**
 *
 * @author caleb
 */
public class CheckIBSN_10 {
    public static void main(String[] args)
    {
        // Create scanner
        Scanner input = new Scanner(System.in);
        // define vars
        int digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN;
        boolean debug = true;
        // Scan individual numbers
        System.out.print("Enter the first 9 digits of an ISBN as an integer: ");
        inputISBN = input.nextInt(); // Get the first 9 digits of the ISBN
        
        
        // Divide the number up into 9 digits
        digit1 = inputISBN / 100000000 % 10;
        digit2 = inputISBN / 10000000 % 10;
        digit3 = inputISBN / 1000000 % 10;
        digit4 = inputISBN / 100000 % 10;
        digit5 = inputISBN / 10000 % 10;
        digit6 = inputISBN / 1000 % 10;
        digit7 = inputISBN / 100 % 10;
        digit8 = inputISBN / 10 % 10;
        digit9 = inputISBN / 1 % 10;
        //System.out.println(digit1 +"" + digit2 +"" + digit3 +"" + digit4 +"" + digit5 +"" + digit1 +"" + );
        //Print digits for debugging
        if (debug == true)
        {
            System.out.println("inputISBN: " + inputISBN);
            System.out.println("ISBN split into 9 digits: " + (digit1) + " " + (digit2) + " " + (digit3) + " " + (digit4) + " " + (digit5) + " " + (digit6) + " " + (digit7) + " " + (digit8) + " " + (digit9));
        }
        // Calculate!
        outputISBN = ((digit1 * 1) + (digit2 * 2) + (digit3 * 3) + (digit4 * 4) + (digit5 * 5) + (digit6 * 6) + (digit7 * 7) + (digit8 * 8) + (digit9 * 9)) % 11;
        
        //Output
        if (outputISBN == 10)
        {
            System.out.println("The ISBN-10 number is " + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + "X");
        }
        else
        {
            System.out.println("The ISBN-10 number is " + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + outputISBN);
        }
    }
}