请老师看下

请老师看下

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

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小脸 2020-02-07 18:55:36

同学你好,由于同学提供代码不全,老师只测试了展示员工信息。是正确的,继续加油。

测试结果如下图所示:

http://img1.sycdn.imooc.com/climg/5e3d41dc091f6faf05640384.jpg

http://img1.sycdn.imooc.com/climg/5e3d41f20922656d08270535.jpg

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • 提问者 慕沐1233560 #1
    我的职务怎么是空的呢
    2020-02-07 19:00:13
  • 好帮手慕小脸 回复 提问者 慕沐1233560 #2
    你好,由于同学没有提供职务类代码,所以老师注释了对该类的定义。 如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
    2020-02-07 19:13:10
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师