//车辆识别号VIN中字母对应的数值
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Hashtable htbVIN(){
Hashtable ht = new Hashtable();
ht.put("A", 1);
ht.put("B", 2);
ht.put("C", 3);
ht.put("D", 4);
ht.put("E", 5);
ht.put("F", 6);
ht.put("G", 7);
ht.put("H", 8);
ht.put("J", 1);
ht.put("K", 2);
ht.put("L", 3);
ht.put("M", 4);
ht.put("N", 5);
ht.put("P", 7);
ht.put("R", 9);
ht.put("S", 2);
ht.put("T", 3);
ht.put("U", 4);
ht.put("V", 5);
ht.put("W", 6);
ht.put("X", 7);
ht.put("Y", 8);
ht.put("Z", 9);
ht.put("1", 1);
ht.put("2", 2);
ht.put("3", 3);
ht.put("4", 4);
ht.put("5", 5);
ht.put("6", 6);
ht.put("7", 7);
ht.put("8", 8);
ht.put("9", 9);
ht.put("0", 0);
return ht;
}
//车辆识别号中顺序对应的加权系数
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Hashtable htbVIN_JQS(){
Hashtable ht = new Hashtable();
ht.put(1, 8);
ht.put(2, 7);
ht.put(3, 6);
ht.put(4, 5);
ht.put(5, 4);
ht.put(6, 3);
ht.put(7, 2);
ht.put(8, 10);
ht.put(9, 0);
ht.put(10, 9);
ht.put(11, 8);
ht.put(12, 7);
ht.put(13, 6);
ht.put(14, 5);
ht.put(15, 4);
ht.put(16, 3);
ht.put(17, 2);
return ht;
}
// IN可用字符
public static String sKYZF="ABCDEFGHJKLMNPRSTUVWXYZ1234567890";
//检验车辆识别号
@SuppressWarnings("rawtypes")
public static boolean getCheckCode_VIN(String sVIN){
String sJYW = "";
boolean bl = false;
boolean blKYZF = false;
if (sVIN.length() == 17){
int iJQS=0 ,intTemp=0;
Hashtable ht = new Hashtable();
ht = htbVIN();
Hashtable htZM = new Hashtable();
htZM = htbVIN_JQS();
if(!sVIN.startsWith("L")){
bl = false;
}
try{
for (int i = 0; i < sVIN.length(); i++){
if (sKYZF.contains (sVIN.substring(i, i+1))){
blKYZF = true;
int temp1 = (int)ht.get(sVIN.substring(i, i+1));
int temp2 = (int)htZM.get(i+1);
iJQS = iJQS + temp1 * temp2;
}else{
blKYZF = false;
break;//发现不合法字符,直接退出循环
}
}
if (blKYZF){
intTemp = iJQS % 11;
if (intTemp == 10)
sJYW = "X";
else
sJYW = intTemp+"";
String temp = sVIN.charAt(8)+"";
if (sJYW.equals(temp))
bl = true;
}else{
bl = false;
}
}catch(Exception e){
bl = false;
}
}
return bl;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Hashtable htbVIN(){
Hashtable ht = new Hashtable();
ht.put("A", 1);
ht.put("B", 2);
ht.put("C", 3);
ht.put("D", 4);
ht.put("E", 5);
ht.put("F", 6);
ht.put("G", 7);
ht.put("H", 8);
ht.put("J", 1);
ht.put("K", 2);
ht.put("L", 3);
ht.put("M", 4);
ht.put("N", 5);
ht.put("P", 7);
ht.put("R", 9);
ht.put("S", 2);
ht.put("T", 3);
ht.put("U", 4);
ht.put("V", 5);
ht.put("W", 6);
ht.put("X", 7);
ht.put("Y", 8);
ht.put("Z", 9);
ht.put("1", 1);
ht.put("2", 2);
ht.put("3", 3);
ht.put("4", 4);
ht.put("5", 5);
ht.put("6", 6);
ht.put("7", 7);
ht.put("8", 8);
ht.put("9", 9);
ht.put("0", 0);
return ht;
}
//车辆识别号中顺序对应的加权系数
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Hashtable htbVIN_JQS(){
Hashtable ht = new Hashtable();
ht.put(1, 8);
ht.put(2, 7);
ht.put(3, 6);
ht.put(4, 5);
ht.put(5, 4);
ht.put(6, 3);
ht.put(7, 2);
ht.put(8, 10);
ht.put(9, 0);
ht.put(10, 9);
ht.put(11, 8);
ht.put(12, 7);
ht.put(13, 6);
ht.put(14, 5);
ht.put(15, 4);
ht.put(16, 3);
ht.put(17, 2);
return ht;
}
// IN可用字符
public static String sKYZF="ABCDEFGHJKLMNPRSTUVWXYZ1234567890";
//检验车辆识别号
@SuppressWarnings("rawtypes")
public static boolean getCheckCode_VIN(String sVIN){
String sJYW = "";
boolean bl = false;
boolean blKYZF = false;
if (sVIN.length() == 17){
int iJQS=0 ,intTemp=0;
Hashtable ht = new Hashtable();
ht = htbVIN();
Hashtable htZM = new Hashtable();
htZM = htbVIN_JQS();
if(!sVIN.startsWith("L")){
bl = false;
}
try{
for (int i = 0; i < sVIN.length(); i++){
if (sKYZF.contains (sVIN.substring(i, i+1))){
blKYZF = true;
int temp1 = (int)ht.get(sVIN.substring(i, i+1));
int temp2 = (int)htZM.get(i+1);
iJQS = iJQS + temp1 * temp2;
}else{
blKYZF = false;
break;//发现不合法字符,直接退出循环
}
}
if (blKYZF){
intTemp = iJQS % 11;
if (intTemp == 10)
sJYW = "X";
else
sJYW = intTemp+"";
String temp = sVIN.charAt(8)+"";
if (sJYW.equals(temp))
bl = true;
}else{
bl = false;
}
}catch(Exception e){
bl = false;
}
}
return bl;
}