package student;
public class Employee
{
String strEmpID;
char chrGender;
String strTElNumber;
double dblSalary;
public Employee(String strEmpID, char chrGender, String strTElNumber,
double dblSalary)
{
this.strEmpID = strEmpID;
this.chrGender = chrGender;
this.strTElNumber = strTElNumber;
this.dblSalary = dblSalary;
}
public String getStrEmpID()
{
return strEmpID;
}
public void setStrEmpID(String strEmpID)
{
this.strEmpID = strEmpID;
}
public double getDblSalary()
{
return dblSalary;
}
public void setDblSalary(double dblSalary)
{
this.dblSalary = dblSalary;
}
public void raiseSalary(double dblProportion)
{
System.out.println("最终工资:"+dblSalary*(1+dblProportion));
}
public String toString()
{
return "****************员工基本信息****************\n"+"编号:"+strEmpID+"\t性别:"+chrGender+"\t电话号码:"+strTElNumber+"\t工资:"+dblSalary+"\n";
}
}
package student;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
public class EmployeeTest
{
private static String strEmpID;
private static char chrGender;
private static String strTElNumber;
private static double dblSalary;
private static String strOfficeId;
private static String isGoOn;//定义一个(从键盘接受的字符串)是否继续录入的变量
private static boolean isGoOnInput=true;//循环录入的标志
private static boolean isTrue=true;//判断员工类型正确一否的标志
private static boolean isstrEmpIDexsit=true;//判断员工编号是否重复的标志
public static void main(String[] args) throws IOException
{
repeatInputEmployeeInfo();
}
/*********************定义一个方法,用于重复录入员工信息************************/
private static void repeatInputEmployeeInfo() throws IOException
{
HashMap<String, Employee> hm=new HashMap<String, Employee>();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(isGoOnInput)
{
isGoOnInput=false;
isstrEmpIDexsit = inputEmployeeInfo(hm, br, isstrEmpIDexsit);
isTrue = judgeOfEmployeeType(hm, br, isTrue, strEmpID, chrGender,strTElNumber, dblSalary);
judegIsOrNotInputEmployeeInfo(hm, br);
}
}
/*********************定义一个方法,用于重复录入员工信息 END************************/
/************************定义一个方法,判断用户是否循环录入员工信息***********************/
private static void judegIsOrNotInputEmployeeInfo(HashMap<String, Employee> hm, BufferedReader br) throws IOException
{
System.out.println("是否继续录入员工基本信息:(y 继续)(请他键退出)");
isGoOn=br.readLine();
if(isGoOn.equals("y")||isGoOn.equals("Y"))
{
isGoOnInput=true;
isstrEmpIDexsit=true;
isTrue=true;
}
else
{
System.out.println(hm);
isGoOnInput=false;
}
}
/************************定义一个方法,判断用户是否循环录入员工信息 END***********************/
/************************定义一个方法,判断用户输入的员工编号是否已经存在,系统规定员工编号不能重复***********************/
private static boolean inputEmployeeInfo(HashMap<String, Employee> hm,BufferedReader br, boolean isstrEmpIDexsit) throws IOException
{
while(isstrEmpIDexsit)
{
isstrEmpIDexsit=false;
System.out.println("请输入员工编号:");
strEmpID=br.readLine();
if(!hm.isEmpty())
{
if(hm.containsKey(strEmpID))
{
System.out.println("员工编号已经存在,请换一个员工编号");
isstrEmpIDexsit=true;
}
}
}
System.out.println("请输入员工性别:");
chrGender=br.readLine().toCharArray()[0];
System.out.println("请输入员工电话:");
strTElNumber=br.readLine();
System.out.println("请输入员工的工资:");
dblSalary=Double.parseDouble(br.readLine());
return isstrEmpIDexsit;
}
/************************定义一个方法,判断用户输入的员工编号是否已经存在,系统规定员工编号不能重复 END*********************/
/************************定义一个方法,判断用于录入员工的类型***********************/
private static boolean judgeOfEmployeeType(HashMap<String, Employee> hm,BufferedReader br, boolean isTrue, String strEmpID, char chrGender,String strTElNumber, double dblSalary) throws IOException
{
while(isTrue)
{
isTrue=false;
System.out.println("请选择输入的员工类型:1 经理信息 2 员工信息");
String type=br.readLine();
if(type.equals("1"))//是经理信息
{
System.out.println("请输入经理的办公室编号:");
strOfficeId=br.readLine();
Manager manager=new Manager(strEmpID,chrGender,strTElNumber,dblSalary,strOfficeId);
hm.put(strEmpID, manager);
}
else if(type.equals("2"))
{
Employee employee=new Employee(strEmpID,chrGender,strTElNumber,dblSalary);
hm.put(strEmpID, employee);
}
else
{
System.out.println("请选择的员工类型有误!,请重新选择1: 经理信息 2: 员工信息");
isTrue=true;
}
}
return isTrue;
}
/************************定义一个方法,判断用于录入员工的类型 END***********************/
}
package student;
public class Manager extends Employee
{
String strOfficeId;
double dblBonus;
public Manager(String strEmpID, char chrGender, String strTElNumber,double dblSalary, String strOfficeId)
{
super(strEmpID, chrGender, strTElNumber, dblSalary);
this.strOfficeId = strOfficeId;
}
public String getStrOfficeId()
{
return strOfficeId;
}
public void setStrOfficeId(String strOfficeId)
{
this.strOfficeId = strOfficeId;
}
public double getDblBonus()
{
return dblBonus;
}
public void setDblBonus(double dblBonus)
{
this.dblBonus = dblBonus;
}
public void raiseSalary(double dblProportion)
{
System.out.println("最终工资:"+dblSalary*(1+dblProportion)*(1+0.1));
}
@Override
public String toString()
{
return "****************经理基本信息****************\n"+"编号:"+strEmpID+"\t性别:"+chrGender+"\t电话号码:"+strTElNumber+"\t工资:"+dblSalary+"\t办公室编号:"+strOfficeId+"\n";
}
}