import javax.swing.* ;

public class VINChecker

{

public static void main ( String [ ] args )

{

String vinNumber ;

String illegalCharactersFound = "" ;

boolean validVIN = false ;

boolean lastFour = false ;

boolean checkForSymbols = false ;

boolean lengthSeventeen = false ;

boolean checkExcluededLetters = false ;

boolean checkIllegalCharacters = false ;

boolean allSymbolsFound = false ;

int [ ] weightMultiply = { 8 , 7 , 6 , 5 , 4 , 3 , 2 , 10 , 0 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 } ;

int [ ] characterValue = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 1 , 2 , 3 , 4 , 5 , 7 , 8 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;

String alphabetValue = "ABCDEFGHJKLMNPRSTUVWXYZ" ;

char [ ] alphabetChar = new char [ 23 ] ;

int [ ] characterAsInt = new int [ 17 ] ;

int [ ] characterAsIntMultiplied = new int [ 17 ] ;

int productToCheck = 0 ;

int finalProductToCheck = 0 ;

int [ ] zeroToNineInt = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;

String zeroToNineString = "0123456789" ;

char [ ] zeroToNine = new char [ 23 ] ;

char [ ] charVIN = new char [ 17 ] ;

vinNumber = JOptionPane . showInputDialog ( null , "Enter a VIN Number." ) ;

vinNumber = vinNumber. toUpperCase ( ) ;

if ( vinNumber. length ( ) != 17 )

{

JOptionPane . showMessageDialog ( null , "Invalid VIN. The VIN must consist of 17 characters." ) ;

}

else if ( vinNumber. length ( ) == 17 )

{

lengthSeventeen = true ;

}

if ( lengthSeventeen == true && Character . isDigit ( vinNumber. charAt ( 13 ) ) && Character . isDigit ( vinNumber. charAt ( 14 ) ) &&

Character . isDigit ( vinNumber. charAt ( 15 ) ) && Character . isDigit ( vinNumber. charAt ( 16 ) ) )

{

lastFour = true ;

}

else if ( lengthSeventeen == true && lastFour != true )

{

JOptionPane . showMessageDialog ( null , "Invalid VIN. The last four characters must be digits." ) ;

}

if ( lengthSeventeen == true && lastFour == true && Character . isLetterOrDigit ( vinNumber. charAt ( 0 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 1 ) ) &&

Character . isLetterOrDigit ( vinNumber. charAt ( 2 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 3 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 4 ) ) &&

Character . isLetterOrDigit ( vinNumber. charAt ( 5 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 6 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 7 ) ) &&

Character . isLetterOrDigit ( vinNumber. charAt ( 8 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 9 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 10 ) ) &&

Character . isLetterOrDigit ( vinNumber. charAt ( 11 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 12 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 13 ) ) &&

Character . isLetterOrDigit ( vinNumber. charAt ( 14 ) ) && Character . isLetterOrDigit ( vinNumber. charAt ( 15 ) ) &&

Character . isLetterOrDigit ( vinNumber. charAt ( 16 ) ) )

{

checkForSymbols = true ;

}

else if ( lengthSeventeen == true && lastFour == true && checkForSymbols != true )

{

for ( int p = 0 ; p < 17 ; p ++ )

{

if ( Character . isLetterOrDigit ( vinNumber. charAt ( p ) ) != true )

{

illegalCharactersFound = illegalCharactersFound + vinNumber. charAt ( p ) + " " ;

}

if ( p == 16 )

{

allSymbolsFound = true ;

}

}

if ( allSymbolsFound == true )

{

JOptionPane . showMessageDialog ( null , "Invalid VIN. Illegal characters: " + illegalCharactersFound ) ;

}

}

if ( vinNumber. indexOf ( 'I' ) == - 1 && vinNumber. indexOf ( 'O' ) == - 1 && vinNumber. indexOf ( 'Q' ) == - 1 )

{

checkExcluededLetters = true ;

}

else if ( vinNumber. indexOf ( 'I' ) != - 1 || vinNumber. indexOf ( 'O' ) != - 1 || vinNumber. indexOf ( 'Q' ) != - 1 )

{

JOptionPane . showMessageDialog ( null , "Invalid VIN. The VIN must NOT contain the letters I, O or Q." ) ;

}

if ( lengthSeventeen == true && lastFour == true && checkExcluededLetters == true && checkForSymbols == true )

{

validVIN = true ;

JOptionPane . showMessageDialog ( null , "VIN is valid, now validating the check digit." ) ;

}

if ( validVIN == true )

{

for ( int c = 0 ; c < 17 ; c ++ )

{

charVIN [ c ] = vinNumber. charAt ( c ) ;

}

for ( int a = 0 ; a < 23 ; a ++ )

{

alphabetChar [ a ] = alphabetValue. charAt ( a ) ;

}

for ( int d = 0 ; d < 10 ; d ++ )

{

zeroToNine [ d ] = zeroToNineString. charAt ( d ) ;

}

for ( int i = 0 ; i < 17 ; i ++ )

{

for ( int b = 0 ; b < 23 ; b ++ )

{

if ( charVIN [ i ] == alphabetChar [ b ] )

{

characterAsInt [ i ] = characterValue [ b ] ;

}

else if ( charVIN [ i ] == zeroToNine [ b ] )

{

characterAsInt [ i ] = zeroToNineInt [ b ] ;

}

}

}

}

for ( int z = 0 ; z < 17 ; z ++ )

{

characterAsIntMultiplied [ z ] = weightMultiply [ z ] * characterAsInt [ z ] ;

}

productToCheck = characterAsIntMultiplied [ 0 ] + characterAsIntMultiplied [ 1 ] + characterAsIntMultiplied [ 2 ] + characterAsIntMultiplied [ 3 ] +

characterAsIntMultiplied [ 4 ] + characterAsIntMultiplied [ 5 ] + characterAsIntMultiplied [ 6 ] + characterAsIntMultiplied [ 7 ] +

characterAsIntMultiplied [ 9 ] + characterAsIntMultiplied [ 10 ] + characterAsIntMultiplied [ 11 ] + characterAsIntMultiplied [ 12 ] +

characterAsIntMultiplied [ 13 ] + characterAsIntMultiplied [ 14 ] + characterAsIntMultiplied [ 15 ] + characterAsIntMultiplied [ 16 ] ;

finalProductToCheck = productToCheck % 11 ;

if ( finalProductToCheck == characterAsInt [ 8 ] )

{

JOptionPane . showMessageDialog ( null , "Check digit matches." ) ;

JOptionPane . showMessageDialog ( null , "VIN: " + vinNumber + "

World Manufacturer Identification: " + charVIN [ 0 ] + charVIN [ 1 ] + charVIN [ 2 ] +

"

Country: " + charVIN [ 0 ] + "

Manufacturer: " + charVIN [ 1 ] + "

Make: " + charVIN [ 2 ] + "

Vehicle Description Section: " +

charVIN [ 3 ] + charVIN [ 4 ] + charVIN [ 5 ] + charVIN [ 6 ] + charVIN [ 7 ] + "

Check Digit: " + charVIN [ 8 ] + "

Vehicle Identification Section: " +

charVIN [ 9 ] + charVIN [ 10 ] + charVIN [ 11 ] + charVIN [ 12 ] + charVIN [ 13 ] + charVIN [ 14 ] + charVIN [ 15 ] + charVIN [ 16 ] + "

Model Year: " +

charVIN [ 9 ] + "

Plant: " + charVIN [ 10 ] + "

Sequential Production Number: " + charVIN [ 11 ] + charVIN [ 12 ] + charVIN [ 13 ] + charVIN [ 14 ]

+ charVIN [ 15 ] + charVIN [ 16 ] ) ;

}

else

{

JOptionPane . showMessageDialog ( null , "Invalid VIN. Check Digit is incorrect!" ) ;

}

}