您的位置:首页 > 编程语言

组织机构代码生成器

2018-01-15 13:24 477 查看
/**
* 全国组织机构代码校验码生成程序
* 00251805 7 中共温州市委办公室
* 00251807 3 中共温州市委组织部
* 00251808 1 中共温州市委老干部局 沈伟 2002-04-09 2008-05-05 0.0000 详细
* 00251809 X
**/
public class G_Code {
public static char[] a = new char[8];

public String jy(char[] a) {
int[] ww = { 3, 7, 9, 10, 5, 8, 4, 2 };

int[] cc = new int[8];
int DD = 0;
int C9 = 0;

for (int i = 0; i < 8; i++) {
cc[i] = a[i];
if (47 < cc[i] && cc[i] < 58)
cc[i] = cc[i] - 48;
else
cc[i] = cc[i] - 65;
}
for (int i = 0; i < 8; i++) {
DD += cc[i] * ww[i];
}
C9 = 11 - DD % 11;
if (C9 == 10) {
for (int i = 0; i < 8; i++)
System.out.print(G_Code.a[i]);
System.out.println("-X");
return new String(a) + "-X";
} else if (C9 == 11) {
for (int i = 0; i < 8; i++)
System.out.print(G_Code.a[i]);
System.out.println("-" + (char) (48));
return new String(a) + "-" + (char) (48);
} else {
for (int i = 0; i < 8; i++)
System.out.print(G_Code.a[i]);
System.out.println("-" + (char) (C9 + 48));
return new String(a) + "-" + (char) (C9 + 48);
}

}
/*
* public static void main(String[] args){ try{
*
* System.out.println("请输入长8位的本体代码!"); for(int i=0;i<8;i++){
*
*
* G_Code.a[i] =(char)System.in.read(); } }catch (IOException e) { } G_Code
* G=new G_Code(); G.jy(a);
*
* }
*/
}

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class UI extends JFrame implements ActionListener{
JPanel panel;
JLabel oneLabel;
JButton genButton;
JTextField oneTextField;
JTextField threeTextField;

public UI() {
super("组织机构代码生成器");
panel = new JPanel();
panel.setBackground(new Color(192, 192, 192));
panel.setLayout(new FlowLayout());
this.add(panel);
oneLabel = new JLabel("请输入长8位的本体代码!");

oneTextField = new JTextField(15);

threeTextField = new JTextField(15);
genButton = new JButton("生成校验码");
oneTextField.addActionListener(this);
genButton.addActionListener(this);
panel.add(oneLabel);
panel.add(oneTextField);
panel.add(genButton);
panel.add(threeTextField);
this.setBounds(200, 100, 200, 240);
this.setResizable(true);
this.setVisible(true);

this.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
System.exit(0);
}
});
}

public static void main(String[] args) {
new UI();

}
@Override
public void actionPerformed(ActionEvent e) {

String one = oneTextField.getText().trim();
char[] a = new char[8];
for (int i = 0; i<8 ; i++)
a[i] = one.charAt(i);
String all = new G_Code().jy(a);
threeTextField.setText(String.valueOf(all));
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  代码 生成器 组织