package com02;import com01.com001;import com01.com002;import com01.com004;public class com003 { /**測(cè)試類 * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub com001 x1= new com001("經(jīng)理","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("經(jīng)營(yíng)部","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()+":?jiǎn)T工有"+x4.getSum()+"個(gè)"); System.out.println(x5.getDepartment()+":?jiǎn)T工有"+x5.getSum()+"個(gè)"); }}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職位編號(hào):"+this.getMycom001().getJobnamber()+"\n部門:"+this.getMycom002().getDepartment()+"\n部門編號(hào):"+this.getMycom002().getDenamber(); return str; }
我想統(tǒng)計(jì)一下部門個(gè)數(shù),但是總感覺不對(duì)
慕姐444698
2019-08-06 22:20:59