没有运行结果,麻烦老师看下是怎么回事,谢谢
package com.office.info; /* * 创建部门类 */ public class department{ private String departmentnum;//部门编号 private String departmentname;//部门名称 private staff[] departmentstaff;//部门员工信息 public department(String departmentnum,String departmentname,staff[] departmentstaff){ this.setDepartmentnum(departmentnum); this.setDepartmentname(departmentname); this.setDepartmentstaff(departmentstaff); } public String getDepartmentnum(){ return departmentnum; } public void setDepartmentnum(String departmentnum) { this.departmentnum = departmentnum; } public String getDepartmentname() { return departmentname; } public void setDepartmentname(String departmentname) { this.departmentname = departmentname; } public staff[] getDepartmentstaff() { return departmentstaff; } public void setDepartmentstaff(staff[] departmentstaff) { this.departmentstaff = departmentstaff; } /* * 统计该部门员工个数 */ public int count(staff[] staff){ int count=0; for(int i=0;i<staff.length;i++){ if(staff[i]!=null){ count++; } } return count; } } package com.office.info; /* * 创建职务类 */ public class duty { private String dutynum;//职务编号 private String dutyname;//职务名称 public duty(String dutynum,String dutyname){ this.setDutynum(dutynum); this.setDutyname(dutyname); } public String getDutynum() { return dutynum; } public void setDutynum(String dutynum) { this.dutynum = dutynum; } public String getDutyname() { return dutyname; } public void setDutyname(String dutyname) { this.dutyname = dutyname; } } package com.office.info; /* * 创建员工类 */ public class staff { private String staffname;//员工姓名 private String staffnum;//员工工号 private int age;//员工年龄 private String sex;//员工性别 private department depart;//所属部门 private String du;//职务信息 public staff(String staffname,String staffnum,String sex,int age,String du){ this.setStaffname(staffname); this.setStaffnum(staffnum); this.setAge(age); this.setSex(sex); this.setDu(du); } public String getStaffname() { return staffname; } public void setStaffname(String staffname) { this.staffname = staffname; } public String getStaffnum() { return staffnum; } public void setStaffnum(String staffnum) { this.staffnum = staffnum; } public int getAge() { return age; } /* * 限定年龄只能是18--65之间,反之则设置默认为18岁 */ public void setAge(int age) { if(this.age>=18&&this.age<=65){ this.age = age; }else{ this.age=18; } } public String getSex() { return sex; } public void setSex(String sex) { if(sex.equals("女")){ this.sex = "女"; }else { this.sex = "男"; } } public department getDepart() { return depart; } public void setDepart(department depart) { this.depart = depart; } public String getDu() { return du; } public void setDu(String du) { this.du = du; } /* * 员工自我介绍信息 */ public String intro(){ String str="姓名:"+this.getStaffname()+"\n工号:" +this.getStaffnum()+"\n性别:"+this.getSex()+"\n年龄:"+this.getAge()+"\n职务:"+this.getDu(); return str; } } package com.office.test; import com.office.info.staff; import com.office.info.duty; /* * 创建测试类 */ public class officetest { public static void main(String[] args) { // TODO Auto-generated method stub duty du1=new duty("001","经理"); staff st1=new staff("张铭","S001","男",29,du1.getDutyname()); System.out.println(st1.intro()); } }
0
收起
正在回答 回答被采纳积分+1
2回答
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星