自己写的员工信息的录入

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";
	}
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值