public static String isbn ( ) { StringBuffer stringBuffer = new StringBuffer ( "09" ) ; stringBuffer . append ( String . format ( "%06d" , JDefaultNumber . randomIntBetweenTwoNumbers ( 0 , 49999 ) ) ) ; stringBuffer . append ( String . format ( "%02d" , JDefaultNumber . randomIntBetweenTwoNumbers ( 0 , 99 ) ) ) ; String numberString = stringBuffer . toString ( ) ; int number = Integer . parseInt ( numberString ) ; int sum = 0 ; for ( int i = 2 ; i <= 10 ; i ++ ) { int digit = number % 10 ; // rightmost digit sum = sum + i * digit ; number = number / 10 ; } // Determine check digit, use X for 10 String checkDigit = null ; if ( sum % 11 == 1 ) { checkDigit = "X" ; } else if ( sum % 11 == 0 ) { checkDigit = "0" ; } else { checkDigit = ( 11 - ( sum % 11 ) ) + "" ; } // System.out.println("The full ISBN number is " + numberString+checkDigit); String returnString = stringBuffer . toString ( ) ; returnString = returnString . substring ( 0 , 1 ) + "-" + returnString . substring ( 1 , 7 ) + "-" + returnString . substring ( 7 , 9 ) + "-" + checkDigit ; return returnString ; }
Generates an English Language Publisher Code in the range of 0 - 900000 - xx - x to 0 - 949999 - xx - x