首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

呼救!

2011-12-04 
求救!!!import java.io.BufferedReaderimport java.io.IOExceptionimport java.io.InputStreamReaderim

求救!!!


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class yuangong {
String name, sex, birthday, telephone, email, enducation;
int pay;
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));

public yuangong(String aname, String asex, String abirthday,
String atelephone, String aemail, String aenducation, int apay) {
name = aname;
sex = asex;
birthday = abirthday;
telephone = atelephone;
email = aemail;
enducation = aenducation;
pay = apay;
}

public void nameInput() {// 姓名的输入
try {
String N=new String();
boolean b=true;
while(b){
N = bin.readLine();
if(!isNameNumericRegex(N)){
System.out.println("格式错误!");
}
else{
b=false;
continue;
}
}
}catch (IOException e) {
e.printStackTrace();

}
}

void sexTnput() {// 性别的输入
try {
String s=new String();
boolean b=true;
while(b){
s = bin.readLine();
if(!isSexNumericRegex(s)){
System.out.println("格式错误!请输入男或女");
continue;
}
else{
s=bin.readLine();
b=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

void birthdayInput() {// 生日的输入
try {
String bir=new String();
boolean b=true;
while(b){
if(!BirthdayNumberiRecgex(bir)){
System.out.println("格式错误!");
continue;
}
else{
bir=bin.readLine();
b=false;
}
}
} catch (IOException e1) {
e1.printStackTrace();
}
}

private boolean BirthdayNumberiRecgex(String bir) {
// TODO Auto-generated method stub
return false;
}

/*private boolean BirthdayNumberiRecgex(String bir) {
// TODO Auto-generated method stub
return false;
}*/

void telephoneInput() {// 电话的输入
try {
Integer tel=new Integer(pay);
boolean b=true;
while(b){
tel = Integer.parseInt(bin.readLine());
if(!isTelNumericRegex(tel)){
System.out.println("格式输入错误!请重新输入");
}
else{
b=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

void emailInput() {// 邮箱的输入
try {
String e=new String();
boolean b=true;
while(b){
if(!isEmailNumericRegex(e)){
System.out.println("格式错误!请重新输入");
continue;
}
else{
email = bin.readLine();
b=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

void enducationInput() {// 学历的输入
try {
String endu=new String();
boolean b=true;
while(b){
if(!isEduNumericRegex(endu)){
System.out.println("格式错误!请重新输入");
continue;
}
else{
enducation = bin.readLine();
b=false; 
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

private boolean isEduNumericRegex(String endu) {
// TODO Auto-generated method stub
return false;
}

void payInput() {//工资的输入
try {
Integer pay=new Integer(0);
boolean b=true;
while(b){
pay = Integer.parseInt(bin.readLine());
if(!isPayNumericRegex(pay)){
System.out.println("格式错误!请重新输入");
continue;
}
else{
b=false;
}

}catch (IOException e) {
e.printStackTrace();
}


}
private boolean isPayNumericRegex(Integer pay2) {
// TODO Auto-generated method stub
return false;
}

public String toString(){
return getClass().getName()+"姓名:"+name+",性别:"+sex+",生日"+birthday+
",电话:"+telephone+",邮箱:"+email+"学历:"+enducation;
}

public static final boolean isNameNumericRegex(String str) {
Pattern name = Pattern.compile("^[a-zA-Z]{1}[a-zA-Z|-|_]{2-16}[a-zA-Z0-9]{1}$");//姓名的正则表达式
Matcher matchern = name.matcher(str.trim());
return matchern.matches();

public static final boolean isSexNumericRegex(String str){
Pattern sex=Pattern.compile("^[男]|[女]$"); //性别的正则表达式
Matcher matcherS=sex.matcher(str.trim());
return matcherS.matches();
}
public static final boolean isDateNumericRegex(String str){
Pattern birthday=Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$");//生日的正则表达式
Matcher matcherB=birthday.matcher(str.trim());
return matcherB.matches();
}
public static final boolean isTelNumericRegex(Integer tel){
Pattern telephone=Pattern.compile("^1\\d{10}$");//电话的正则表达式
Matcher matcherT=telephone.matcher(tel.trim());//这里trim显示错误
return matcherT.matches();
}
public static final boolean isEmailNumericRegex(String str){
Pattern email=Pattern.compile("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");//邮箱的正则表达式
Matcher matcherE=email.matcher(str.trim());
return matcherE.matches();
}
public static final boolean isNumericRegex(String str){
Pattern enducation=Pattern.compile("[高中]|[本科]|[硕士]]");//学历的正则表达式
Matcher matcherED=enducation.matcher(str.trim());
return matcherED.matches();
}

public static void main(String args[]) {
yuangong yg = new yuangong("", "", "", "", "", "", 0);
System.out.println("请输入姓名:");
yg.nameInput();
//System.out.println("yg.name="+yg.name);
System.out.println("请输入性别:");
yg.sexTnput();
System.out.println("请输入出生年月:");
yg.birthdayInput();
System.out.println("请输入手机号:");
yg.telephoneInput();
System.out.println("请输入邮箱:");
yg.emailInput();
System.out.println("请输入学历:");
yg.enducationInput();
System.out.println("该员工信息为:"+yg);

}

}
这个东东运行怎么不行额,中间的几个错误也不知道什么,谢谢各位高手。我弄了好久了

[解决办法]
出问题的第一行改成

Java code
Pattern name = Pattern.compile("^[a-zA-Z]{1}[a-zA-Z|-|_]{2,16}[a-zA-Z0-9]{1}$");//姓名的正则表达式 

热点排行