编写员工类,实现员工的信息输出 要求: (1)属性:编号、姓名、职位、入职日期、基本工资、奖金 (2)两个构造方法和全部getter和setter (3)自定义的方法:toString()方法返回员工信息的字符串、getSalary()方法根据基本工资和奖金计算工资。 (4)单独编写测试类,测试类的全部功能。
如遇帮助,采纳一下吧
//Employe类 基本信息
import java.util.Date;
public class Employee {
private String name;
private double salary;
private String sex;
private Date birthday;
public Employee(){}
public Employee(String name,double salary,String sex,Date birthday){
this.name = name;
this.salary = salary;
this.sex = sex;
this.birthday =birthday;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
//Company 类
import java.util.ArrayList;
import java.util.List;
public class Company {
private List list = new ArrayList();
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
}
//Test_main 测试
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d =null;
Company c = new Company();
while(true){
System.out.println("1.新增");
System.out.println("2.显示");
System.out.println("3.退出");
int n =s.nextInt();
if(n == 1){
System.out.println("输入姓名");
String name = s.next();
System.out.println("输入工资");
double salary = s.nextDouble();
System.out.println("输入性别");
String sex = s.next();
System.out.println("输入生日");
String birthday =s.next();
try {
d = sdf.parse(birthday);
} catch (ParseException e1) {
// TODO Auto-generated catch block
System.out.println("出生日期有误");
}
Employee e = new Employee();
e.setName(name);
e.setBirthday(d);
e.setSalary(salary);
e.setSex(sex);
c.getList().add(e);
continue;
}else
if(2 == n)
{
System.out.println("姓名"+"\t"+"工资"+"\t"+"性别"+"\t"+"出生日期");
List list = c.getList();
for(int i = 0; i < list.size(); i++){
Employee e = list.get(i);
System.out.println(e.getName()+"\t"+e.getSalary()+"\t"+e.getSex()+"\t"+e.getBirthday().toLocaleString());
}
}else
if(3 == n)
{
break;
}else {
break;
}
}
}
}