import java.util.Date;
public class Employee {
private String name;
private String department;
private Date birthDay;
private Date hireDate;
private int workingHours;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Date getBirthday() {
return birthDay;
}
public void setBirthday(Date birthDay) {
this.birthDay = birthDay;
}
public Date getHireDate() {
return hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
public int getWorkingHours() {
return workingHours;
}
public void setWorkingHours(int workingHours) {
this.workingHours = workingHours;
}
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", department='" + department + '\'' +
", birthDay=" + birthDay +
", hireDate=" + hireDate +
", workingHours=" + workingHours +
'}';
}
public Employee(String name,String department,Date birthDay,Date hireDate){
this.name=name;
this.department=department;
this.birthDay=birthDay;
this.hireDate=hireDate;
}
}
//设置这个类,并保存他的属性;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class EmployeeManagerSupport {
public static Employee[] getInfo(){
Employee[] emp = new Employee[5];//确定员工类数组的长度
try {
Employee emp1 = new Employee(“张无忌”, “人事部”, new SimpleDateFormat(“yyyy-MM-dd”).
parse(“1989-10-20”), new SimpleDateFormat(“yyyy-MM-dd”).parse(“2010-10-20”));
Employee emp2 = new Employee(“任盈盈”, “市场部”, new SimpleDateFormat(“yyyy-MM-dd”).
parse(“1992-11-20”), new SimpleDateFormat(“yyyy-MM-dd”).parse(“2017-10-20”));
Employee emp3 = new Employee(“向问天”, “人事部”, new SimpleDateFormat(“yyyy-MM-dd”).
parse(“1971-5-20”), new SimpleDateFormat(“yyyy-MM-dd”).parse(“1999-10-20”));
Employee emp4 = new Employee(“练霓裳”, “研发部”, new SimpleDateFormat(“yyyy-MM-dd”).
parse(“1980-10-26”), new SimpleDateFormat(“yyyy-MM-dd”).parse(“2014-10-20”));
Employee emp5 = new Employee(“张三丰”, “研发部”, new SimpleDateFormat(“yyyy-MM-dd”).
parse(“1976-4-22”), new SimpleDateFormat(“yyyy-MM-dd”).parse(“2000-10-20”));
emp[0] = emp1;
emp[1] = emp2;
emp[2] = emp3;
emp[3] = emp4;
emp[4] = emp5;
}catch(Exception e){
e.printStackTrace();
}
return emp;
}
}
//把实例化的这些类保存到emp这个数组中;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class EmployeeManagerSupport2 {
Employee[] emp = EmployeeManagerSupport.getInfo();
public void input(EmployeeManagerSupport emp) {
if (emp == null) {
System.out.println("插入员工信息失败,人员信息不能为空");
} else {
System.out.println("插入员工信息成功!");
}
}
public List findEmp(int months) throws ParseException {
List emp2=new ArrayList();
for (int i = 0; i < emp.length; i++) {
Date hireDate=emp[i].getHireDate();
String str=new SimpleDateFormat("yyyy-MM-dd").format(hireDate);//将日期转化为指定模式的字符串日期
Date date=new SimpleDateFormat("yyyy-MM-dd").parse(str);//将字符串类型日期转化为Date类型日期
long temp=date.getTime();//入职日期转化为毫秒
long times=(long)1000*60*60*24*30;
Date newDate=new Date();//取得当前时间
long newDatelong=newDate.getTime();//取得当前时间的毫秒数
long difference=newDatelong-temp;//取得总工作时间(毫秒数)
long month=difference/times;//取得工作了多少个月
if(month>months){
emp2.add(emp[i]);//符合条件的就加入emp2这个Arraylist集合中
}
}
return emp2;
}
public List findEmp(Date date){
List emp3=new ArrayList();
for (int i = 0; i <emp.length ; i++) {
if(emp[i].getBirthday().before(date)){
emp3.add(emp[i]);
}
}
return emp3;
}
}
制造三个方法,第一个方法插入员工信息,第二个方法找出符合二级涨薪的条件,第三个方法找出符合优秀员工奖的员工。
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class Hello {
public static void main(String[] args) throws Exception{
EmployeeManagerSupport2 empn=new EmployeeManagerSupport2();
try{
List emps=empn.findEmp(80);
System.out.println(“以下员工提薪两级”);
for (Object temp:emps){
System.out.println(temp.toString());
}
}catch (Exception e){
e.printStackTrace();
}
try{
Date date=new SimpleDateFormat(“yyyy-MM-dd”).parse(“1978-11-18”);
List emp5=empn.findEmp(date);
System.out.println(“以下员工为突出贡献奖”);
for (Object temp:emp5){
System.out.println(temp.toString());
}
}catch(Exception e){
e.printStackTrace();
}
}
}
//测试。