老师,我的统计职员方法实在不会写,是不是我其他方法存在缺陷,代码如下..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | package com.my.staff; import com.my.administration.Administration; import com.my.position.Job; /** * 员工类 * @author Administrator * */ public class Staff { private String staffName; //员工姓名 private String staffNo; //工号 private String staffSex; //性别 private int staffAge; //年龄 private Administration admin; /** * 无参构造方法 */ public Staff() { } public Staff(String staffName, String staffNo, String staffSex, int staffAge,Administration admin) { super (); this .setStaffName(staffName); this .setStaffNo(staffNo); this .setStaffAge(staffAge); this .setStaffSex(staffSex); this .setAdmin(admin); } public String getStaffName() { return staffName; } public void setStaffName(String staffName) { this .staffName = staffName; } public String getStaffNo() { return staffNo; } public void setStaffNo(String staffNo) { this .staffNo = staffNo; } public String getStaffSex() { return staffSex; } public void setStaffSex(String staffSex) { this .staffSex = staffSex; } public int getStaffAge() { if ( this .staffAge< 18 ) staffAge= 18 ; return staffAge; } public void setStaffAge( int staffAge) { this .staffAge = staffAge; } public Administration getAdmin() { return admin; } public void setAdmin(Administration admin) { this .admin = admin; } /** * * @return 员工的基本信息 */ public String showStaff() { String str= "姓名:" + this .getStaffName()+ "\n工号:" + this .getStaffNo() + "\n性别:" + this .getStaffSex()+ "\n年龄:" + this .getStaffAge() + "\n职务:" + this .getAdmin().getAdminName()+ this .getAdmin().getJob().getJobName(); return str; } } |
package com.my.administration;
import com.my.position.Job;
import com.my.staff.Staff;
//部门类
public class Administration {
private String adminName;
private Job job;
private Staff[] staff;
private int staffNo;
/**
* 无参构造方法
*/
public Administration() {
}
public Administration(String adminName,Job job) {
super();
this.setAdminName(adminName);
this.setJob(job);
}
public String getAdminName() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
public Job getJob() {
if(this.job==null)
job=new Job();
return job;
}
public void setJob(Job job) {
this.job = job;
}
public Staff[] getStaff() {
if(staff==null)
staff=new Staff[10];
return staff;
}
public void setStaff(Staff[] staff) {
this.staff = staff;
}
public int getStaffNo() {
return staffNo;
}
public void setStaffNo(int staffNo) {
this.staffNo = staffNo;
}
public void addStaff(Staff staff) {
}
}
package com.my.position;
//职员类
public class Job {
private String jobName;
public Job() {
super();
}
public Job(String jobName) {
super();
this.setJobName(jobName);
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
}
package com.my.test;
import com.my.administration.Administration;
//测试类
import com.my.position.Job;
import com.my.staff.*;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Job job=new Job("职员");
Job job1=new Job("助理");
Job job2=new Job("经理");
Administration admin=new Administration("市场部",job);
Administration admin1=new Administration("市场部",job1);
Administration admin2=new Administration("市场部",job2);
Administration admin3=new Administration("人事部",job);
Administration admin4=new Administration("人事部",job1);
Administration admin5=new Administration("人事部",job2);
Staff staff=new Staff("摩根弗里曼", "S001", "男", 17,admin);
Staff staff1=new Staff("金凯瑞", "S002", "男", 19,admin1);
Staff staff2=new Staff("汤姆克鲁斯", "S003", "男", 19,admin2);
Staff staff3=new Staff("摩根弗里曼", "S001", "男", 17,admin3);
Staff staff4=new Staff("金凯瑞", "S002", "男", 19,admin4);
Staff staff5=new Staff("汤姆克鲁斯", "S003", "男", 19,admin5);
String str=staff.showStaff();
System.out.println(staff.showStaff());
System.out.println("========================================================");
System.out.println(staff1.showStaff());
System.out.println("========================================================");
System.out.println(staff2.showStaff());
System.out.println("========================================================");
System.out.println(staff3.showStaff());
System.out.println("========================================================");
System.out.println(staff4.showStaff());
System.out.println("========================================================");
System.out.println(staff5.showStaff());
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧