老师,我的这个职务为什么为空?谢谢
package com.imooc.model; public class Department { //成员属性:部门编号、部门名称 private int deptNo; private String deptName; //无参构造 public Department(){ } //带参构造 public Department(int deptNo,String deptName){ this.setDeptNo(deptNo); this.setDeptName(deptName); } public int getDeptNo() { return deptNo; } public void setDeptNo(int deptNo) { this.deptNo = deptNo; } public String getDeptName() { return deptName; } public void setDeptName(String deptName) { this.deptName = deptName; } //输出结果 public String info(){ String str = "部门名称:" + this.getDeptName(); return str; } } package com.imooc.model; public class Post { //成员属性:职务编号、职务名称 private String postNo; private String postName; //无参构造 public Post(){ } //带参构造 public Post(String postNo,String postName){ this.setPostNo(postNo); this.setPostName(postName); } public String getPostNo() { return postNo; } public void setPostNo(String postNo) { this.postNo = postNo; } public String getPostName() { return postName; } public void setPostName(String postName) { this.postName = postName; } //输出结果 public String info(){ String str = "职务名称:" + this.getPostName(); return str; } } package com.imooc.model; public class Employee { // 成员属性:姓名、工号、年龄、性别、所属部门、职务 private String empName; private String empNo; private int empAge; private String empSex; private Department employeedp; private Post employeept; // 无参构造 public Employee() { } // 带参构造 public Employee(String empName, String empNo, String empSex, int empAge) { this.setEmpName(empName); this.setEmpNo(empNo); this.setEmpAge(empAge); this.setEmpSex(empSex); } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName = empName; } public String getEmpNo() { return empNo; } public void setEmpNo(String empNo) { this.empNo = empNo; } public int getEmpAge() { return empAge; } public void setEmpAge(int empAge) { if (empAge >= 18 && empAge <= 65) { this.empAge = empAge; } else { this.empAge = 18; } } public String getEmpSex() { return empSex; } public void setEmpSex(String empSex) { if (empSex.equals("女")) { this.empSex = "女"; } else { this.empSex = "男"; } } public Department getEmployeedp() { if(this.employeedp == null){ this.employeedp = new Department(); } return employeedp; } public void setEmployeedp(Department employeedp) { this.employeedp = employeedp; } public Post getEmployeept() { if(this.employeept == null){ this.employeept = new Post(); } return employeept; } public void setEmployeept(Post employeept) { this.employeept = employeept; } // 输出结果 public String info(Department employeedp,Post employeept) { String str = "姓名:" + this.getEmpName() + "\n工号:" + this.getEmpNo() + "\n性别:" + this.getEmpSex() + "\n年龄:" + this.getEmpAge() + "\n职务:" + this.getEmployeedp().getDeptName() + this.getEmployeept().getPostName(); return str; } } package com.imooc.test; import com.imooc.model.Department; import com.imooc.model.Post; import com.imooc.model.Employee; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub //部门 Department dt1 = new Department(1,"人事部"); Department dt2 = new Department(2,"市场部"); //职务 Post pt1 = new Post("JL","经理"); Post pt2 = new Post("ZL","助理"); Post pt3 = new Post("ZY","职员"); //员工详细信息 Employee emp1 = new Employee("张铭","S001","男",29); Employee emp2 = new Employee("李艾超","S002","女",21); Employee emp3 = new Employee("孙超","S003","男",29); Employee emp4 = new Employee("张美美","S004","女",26); Employee emp5 = new Employee("蓝迪","S005","男",37); Employee emp6 = new Employee("米莉","S006","女",24); System.out.println(emp1.info(dt1,pt1)); } }
30
收起
正在回答 回答被采纳积分+1
1回答
Android零基础入门2018版
- 参与学习 人
- 提交作业 5461 份
- 解答问题 7238 个
此次推出的专题为Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始学习Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星