请老师看下
package com.xiaomin.model;
public class Employees{
//成员属性
private String employeesName;//员工姓名
private String employeesNo;//员工工号
private String employeesSex;//员工性别
private int employeesAge;//员工年龄
private Department empDepartment;//所在部门
private Position empPosition;//职务
public Employees(){
}
//带参构造 包含员工姓名、工号、性别、年龄
public Employees(String employeesName,String employeesNo,String employeesSex,int employeesAge){
this.setEmployeesName(employeesName);
this.setEmployeesNo(employeesNo);
this.setEmployeesSex(employeesSex);
this.setEmployeesAge(employeesAge);
}
//带参构造包含全部 包含姓名、工号、性别、年龄、所在部门、职务
public Employees(String employeesName,String employeesNo,String employeesSex,int employeesAge,Department empDepartment,Position empPosition){
this.setEmployeesName(employeesName);
this.setEmployeesNo(employeesNo);
this.setEmployeesSex(employeesSex);
this.setEmployeesAge(employeesAge);
this.setEmpDepartment(empDepartment);
this.setEmpPosition(empPosition);
}
public String getEmployeesName(){
return employeesName;
}
public void setEmployeesName(String employeesName){
this.employeesName=employeesName;
}
public String getEmployeesNo(){
return employeesNo;
}
public void setEmployeesNo(String employeesNo){
this.employeesNo=employeesNo;
}
public int getEmployeesAge(){
return employeesAge;
}
public void setEmployeesAge(int employeesAge){
if(employeesAge>=18&&employeesAge<=65){
this.employeesAge=employeesAge;
}else{
this.employeesAge=18;
}
// this.employeesAge=employeesAge;
}
public String getEmployeesSex(){
return employeesSex;
}
//限定性别只能是“男”或者“女”,反之则设置默认为"男"
public void setEmployeesSex(String employeesSex){
if(employeesSex.equals("男") || employeesSex.equals("女")){
this.employeesSex=employeesSex;
}else{
this.employeesSex="男";
}
// this.employeesSex=employeesSex;
}
public Department getEmpDepartment(){
return empDepartment;
}
public void setEmpDepartment(Department empDepartment){
this.empDepartment=empDepartment;
}
public Position getEmpPosition(){
return empPosition;
}
public void setEmpPosition(Position empPosition){
this.empPosition=empPosition;
}
public String info(){
String str="姓名:"+this.getEmployeesName()+"\n工号:"+this.getEmployeesNo()+"\n性别:"+this.getEmployeesSex()
+"\n年龄:"+this.getEmployeesAge()+"\n职务:"+this.getEmpPosition();
return str;
}
}
package com.xiaomin.test;
import com.xiaomin.model.Employees;
public class OfficeTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Employees em=new Employees("李四","S0006","男",30,"市场部经理");
System.out.println(em.info());
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星