为了账号安全,请及时绑定邮箱和手机立即绑定

我想统计一下部门个数,但是总感觉不对

我想统计一下部门个数,但是总感觉不对

慕姐444698 2019-08-06 22:20:59
package com02;import com01.com001;import com01.com002;import com01.com004;public class com003 { /**测试类 * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub com001 x1= new com001("经理","bj001"); com001 x2= new com001("助理","bj002"); com001 x3= new com001("员工","bj003"); //************************************************; com002 x4= new com002("人事部","rs001"); com002 x5= new com002("管理部","gl001"); com002 x6= new com002("经营部","jy001"); //************************************************; com004 x7= new com004("张铭",15,"男",x1,x5); System.out.println(x7.show()); System.out.println("................................"); com004 x8= new com004("西西",24,"女",x2,x5); System.out.println(x8.show()); System.out.println("................................"); com004 x9= new com004("李泽",21,"男",x3,x4); System.out.println(x9.show()); System.out.println("................................"); com004 x10= new com004("笔笔",19,"女",x3,x4); System.out.println(x10.show()); System.out.println("................................"); //*************************************************; x4.sh1(x7); x4.sh1(x8); x5.sh1(x9); x4.sh1(x10); //*************************************************; System.out.println(x4.getDepartment()+":员工有"+x4.getSum()+"个"); System.out.println(x5.getDepartment()+":员工有"+x5.getSum()+"个"); }}package com01;/** * 职位类; * @author Administrator * */public class com001 { private String job; private String jobnamber; //*****************************************************; public com001(){ } public com001(String job,String jobnamber){ this.setJob(job); this.setJobnamber(jobnamber); } //******************************************************; public String getJob() { return job; } public void setJob(String job) { this.job = job; } public String getJobnamber() { return jobnamber; } public void setJobnamber(String jobnamber) { this.jobnamber = jobnamber; } package com01;/** * 部门类; * @author Administrator * */public class com002 { private String department; private String denamber; private com004[] mycom004; private int sum; //***********************************************************; public com002(){ } public com002(String department,String denamber){ this.setDepartment(department); this.setDenamber(denamber); } public com002(String department,String denamber,com004[] mycom004,int sum){ this.setDepartment(department); this.setDenamber(denamber); this.setMycom004(mycom004); this.setSum(sum); } //************************************************************; public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public String getDenamber() { return denamber; } public void setDenamber(String denamber) { this.denamber = denamber; } public com004[] getMycom004() { if(this.mycom004==null){ this.mycom004= new com004[100]; } return mycom004; } public void setMycom004(com004[] mycom004) { this.mycom004 = mycom004; } public int getSum() { return sum; } public void setSum(int sum) { this.sum = sum; } //************************************************************; public void sh1(com004 st){ for(int i=0;i<this.getMycom004().length;i++){ if(this.getMycom004()[i]==null){ this.getMycom004()[i]=st; this.sum=i+1; return; } } } }package com01;public class com004 { private String name; private int age; private String sex; private com001 mycom001; private com002 mycom002; //******************************************************; public com004(){ } public com004(String name,int age,String sex){ this.setName(name); this.setAge(age); this.setSex(sex); } public com004(String name,int age,String sex,com001 mycom001,com002 mycom002){ this.setName(name); this.setAge(age); this.setSex(sex); this.setMycom001(mycom001); this.setMycom002(mycom002); }    //******************************************************; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { if(age<18||age>65){ this.age=18; }else     this.age=age; } public String getSex() { return sex; } public void setSex(String sex) { if(sex.equals("男")||sex.equals("女")){ this.sex=sex; }else     this.sex = "男"; } public com001 getMycom001() { return mycom001; } public void setMycom001(com001 mycom001) { this.mycom001 = mycom001; } public com002 getMycom002() { return mycom002; } public void setMycom002(com002 mycom002) { this.mycom002 = mycom002; } //****************************************************; public String show(){ String str="员工信息如下:\n名字:"+this.getName()+"\n年龄:"+this.getAge()+"\n性别:"+this.getSex()+"\n职位:"+this.getMycom001().getJob()+"\n职位编号:"+this.getMycom001().getJobnamber()+"\n部门:"+this.getMycom002().getDepartment()+"\n部门编号:"+this.getMycom002().getDenamber(); return str; }
查看完整描述

2 回答

?
慕仔4242357

TA贡献3条经验 获得超0个赞

没有首行缩进看着太难受了哥

查看完整回答
反对 回复 2019-08-10
  • 2 回答
  • 0 关注
  • 1109 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信