//package app1;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;//迭代器
class Employee
{
private String strEmpID;//员工编号
String chrGender;//性别
String strTelNumber;//电话号码
private double dblSalary;//工资
Employee(String strEmpID,String chrGender,String strTelNumber,double dblSalary)
{
this.setID(strEmpID);
this.chrGender=chrGender;
this.strTelNumber=strTelNumber;
this.setSalary(dblSalary);
}
//无参构造
Employee()
{
}
//一个参数构造
Employee(String chrGender)
{
this.chrGender=chrGender;
}
//设置员工编号
public void setID(String strEmpID)
{
this.strEmpID=strEmpID;
}
//返回员工编号
public String getID()
{
return strEmpID;
}
//设置员工性别
public String getChrGender()
{
return chrGender;
}
//设置员工工资
public void setSalary(double dblSalary)
{
this.dblSalary=dblSalary;
}
//返回员工工资
public double getSalary()
{
return dblSalary;
}
//设置员工电话
public void setTelNumber(String strTelNumber)
{
this.strTelNumber=strTelNumber;
}
//返回员工电话
public String getTelNumber()
{
return strTelNumber;
}
//录入员工信息及输入员工信息
public void Info()throws Exception
{
HashMap<String, Employee> e=new HashMap<String, Employee>();
System.out.println("***************************录入员工信息******************************");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int flag=0;//标记是否继续录入的标志
int i=0;//控制员工的人数
do
{
try
{
flag=0;
System.out.print("员工编号:");
this.strEmpID=br.readLine();
System.out.print("员工性别:");
chrGender=br.readLine();
System.out.print("员工电话:");
this.strTelNumber=br.readLine();
System.out.print("员工工资:");
this.dblSalary=Double.parseDouble(br.readLine());
System.out.println("是否继续录入员工信息(Y 继续 其他键停止录入)");
String ok=br.readLine();
//如果插入的员工信息与已经插入的不一样,则插入成功
if(!e.containsKey(strEmpID))
{
e.put(strEmpID, new Employee(strEmpID,chrGender, strTelNumber,dblSalary));
}
else
{
System.out.println("查入失败,员工编号或电话号码不能重复");
}
if(ok.equals("y")||ok.equals("Y"))//键盘控制事件
{
flag=1;
i++;
}
else//输出员工信息
{
System.out.println("****************员工基本信息表*******************");
System.out.println("员工编号\t\t员工性别\t\t员工电话\t\t员工工资");
for (Iterator<String> it = e.keySet().iterator();it.hasNext();)
{
String str = it.next();
System.out.println(e.get(str).getID()+"\t\t\t"+e.get(str).getChrGender()+"\t\t\t"+e.get(str).getTelNumber()+"\t\t\t"+e.get(str).getSalary());
}
}
}
catch(Exception eee)//捕获输入的错误信息
{
System.out.println("输入错误,请重新输入:");flag=1;continue;
}
}while(flag==1);
}
}
class EmployeeTest
{
public static void main(String []args)
{
Employee ee=new Employee();
try
{
ee.Info();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
};