3-8作业问题
package com.imooc.model; public class Department { //成员属性:部门名称、部门人员信息、部门人数 private String dptNo;//部门编号 private String Subordinatename; //部门名称 private int Subordinatenum; //部门人数 private Persion [] per; //部门人员信息 //无参构造方法 public Department(){ } //有参构造方法 public Department(String Subordinatename){ this.setSubordinatename(Subordinatename); } public int getSubordinatenum() { return Subordinatenum; } public void setSubordinatenum(int subordinatenum) { Subordinatenum = subordinatenum; } public String getSubordinatename() { return Subordinatename; } public void setSubordinatename(String subordinatename) { Subordinatename = subordinatename; } public Persion[] getPer() { if (this.per==null) this.per = new Persion[200]; return per; } public void setPer(Persion[] per) { this.per = per; } public String getDptNo() { return dptNo; } public void setDptNo(String dptNo) { this.dptNo = dptNo; } /*** * 添加部门人数 * @return 将部门人员保存到数组 */ public void addsubor(Persion p){ for (int i = 0; i < this.getPer().length; i++) { if (this.getPer()[i]==null) { p.setDepartment(this); this.getPer()[i]=p; this.Subordinatenum=i+1; return; } } } /*** * 查询该部门职务人数有多少 * @return */ public String info(){ String Str =""; Str=this.getSubordinatename()+"总共有:"+this.getSubordinatenum()+"名员工\n"; return Str; } } package com.imooc.model; public class Persion { /* 员工类: 类型描述:能够描述员工姓名、工号、年龄、性别、所属部门、职务信息 要求: 1、 设定方法限定年龄只能是18--65之间,反之则设置默认为18岁 2、 设定方法限定性别只能是“男”或者“女”,反之则设置默认为"男" 3、 设定方法,实现员工自我介绍信息,将员工信息作为字符串返回 */ private String name; //员工姓名 private String Jobnumber; //员工工号 private int age; //年龄 private String sex; //性别 private Department department; //部门对象 private Post post; //职位对象 //无参构造方法 public Persion(){ } //有参构造方法 public Persion(String name, String jobnumber ,String sex , int age){ this.setName(name); this.setJobnumber(jobnumber); this.setAge(age); this.setSex(sex); } 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("女")) { this.sex ="女"; } else { this.sex = "男"; // this.sex = sex; } } public String getJobnumber() { return Jobnumber; } public void setJobnumber(String jobnumber) { Jobnumber = jobnumber; } public Department getDepartment() { return department; } public void setDepartment(Department department) { this.department = department; } public Post getPost() { return post; } public void setPost(Post post) { this.post = post; } /** * 员工自我介绍信息 * @return 员工信息信息包括:姓名、工号、年龄、性别、所属部门、职务信息 */ public String ziwo(Department clerkDepartment,Post clerkPost){ String str=""; str="姓名:"+this.getName()+"\n工号:"+this.getJobnumber()+"\n性别:"+this.getSex() +"\n年龄:"+this.getAge()+"\n职务:"+clerkDepartment.getSubordinatename()+clerkPost.getClerkPost()+"\n"; return str; } } package com.imooc.model; public class Post { private String clerkPost;//职位 //无参构造方法 public Post(){ } //有参构造方法 public Post(String clerkPost){ this.setClerkPost(clerkPost); } public String getClerkPost() { return clerkPost; } public void setClerkPost(String clerkPost) { this.clerkPost = clerkPost; } } package com.imooc.test; import com.imooc.model.Department; import com.imooc.model.Persion; import com.imooc.model.Post; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Department d1 = new Department("人事部"); Department d2 = new Department("市场部"); Post p =new Post("经理"); Post p1 =new Post("助理"); Post p2 =new Post("职员"); Persion pe =new Persion("张明", "Soo1", "男", 29); System.out.print(pe.ziwo(d1, p)); System.out.println("==============================="); Persion pe1 =new Persion("李艾爱", "Soo2", "女", 21); System.out.print(pe1.ziwo(d1, p1)); System.out.println("==============================="); Persion pe2 =new Persion("孙超", "Soo4", "男", 29); System.out.print(pe2.ziwo(d1, p2)); System.out.println("==============================="); Persion pe3 =new Persion("张美美", "Soo5", "女", 26); System.out.print(pe3.ziwo(d2, p2)); System.out.println("==============================="); Persion pe4 =new Persion("蓝迪", "Soo6", "男", 37); System.out.print(pe4.ziwo(d2, p)); System.out.println("==============================="); Persion pe5 =new Persion("米莉", "Soo7", "女", 24); System.out.print(pe5.ziwo(d2, p2)); System.out.println("==============================="); d1.addsubor(pe); d1.addsubor(pe1); d1.addsubor(pe2); d2.addsubor(pe3); d2.addsubor(pe4); d2.addsubor(pe5); System.out.print(d1.info()); System.out.print(d2.info()); } }
113
收起
正在回答 回答被采纳积分+1
2回答
Java零基础入门18
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星