根据作业要求哪些地方不对?
package operation; /** * 部门类 * @author ThinkPad */ public class Department { // 部门类成员属性:人事部、市场部 private String name; //所在部门员工的个数 private Staff[] myStaffs=new Staff[111]; private int staffNum; //无参构造方法 public Department() { } // 带参构造,实现对属性的全部赋值 public Department(String name) { this.setName(name); this.setMyStaffs(myStaffs); } // // 带参构造,实现对属性的全部赋值 // public Department(String name) { // this.setName(name); // // } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getStaffNum() { return staffNum; } /// /** * 获取学生信息 * @return 保存学生信息的数组 */ public Staff[] getMyStaffs() { return myStaffs; } public void setMyStaffs(Staff[] myStaffs) { this.myStaffs = myStaffs; } public int getstaffNum() { return staffNum; } public void setStaffNum(int staffNum) { this.staffNum = staffNum; } /** * 部门 * @return 人事、市场 */ public String bumen() { String str=this.getName(); return str; } /** * 获取所有部门员工信息 * @param myStaff 姓名 工号 年龄 性别 * @param myDepartment 人事部 市场部 * @param myPosition 经理 助理 职员 * @return 姓名 工号 年龄 性别 部门 职务 */ public String bumen(Staff myStaff,Department myDepartment,Position myPosition) { String str="姓名:"+myStaff.getName()+"\n工号:"+myStaff.getJobNumber()+ "\n年龄:"+myStaff.getAge()+"\n性别:"+myStaff.getGender()+ "\n职务:"+this.getName()+myPosition.getzhiwei(); return str; } public void addStaff(Staff sta) { //1、将员工保存到数组中 for(int a=0;a<getMyStaffs().length;a++) { if(this.getMyStaffs()[a]==null) ; sta.setMydepartment(this); this.getMyStaffs()[a]=sta; //2、将员工个数保存到DepartmentNum this.staffNum=a+1; break; } } }
package operation; /** * 职务类 * @author ThinkPad */ public class Position { //职务类成员属性:经理、助理、职员 private String zhiwei; //无参构造方法 public Position() { } // 带参构造,实现对属性的全部赋值 public Position(String zhiwei) { this.setZhiwei(zhiwei); } public String getzhiwei() { return zhiwei; } public void setZhiwei(String zhiwei) { this.zhiwei = zhiwei; } }
package operation; /** * 员工类 * @author ThinkPad */ public class Staff { //员工类成员属性:姓名、工号、年龄、性别、所属部门、职务信息 private String name;//姓名 private String jobNumber;//工号 private int age;//年龄 private String gender;//性别 private Department myDepartment; //无参构造方法 public Staff() { } // 带参构造,实现对属性的全部赋值 public Staff(String Name,String JobNumber,int Age,String Gender) { this.setName(Name); this.setJobNumber(JobNumber); this.setAge(Age); this.setGender(Gender); } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getJobNumber() { return jobNumber; } public void setJobNumber(String jobNumber) { this.jobNumber = jobNumber; } /** * 限定年龄只能是18--65之间,反之则设置默认为18岁 * @return */ public int getAge() { return age; } public void setAge(int age) { if(age<18||age>65) this.age=18; else this.age = age; } public String getGender() { return gender; } /** * 限制性别只能是“男”或者“女”,反之,强制赋值为“男” * @param gender 传入的性别 */ public void setGender(String gender) { if (gender != "男" && gender != "女") this.gender = "男"; else this.gender = gender; } public Department getMyDepartment() { if(this.myDepartment==null) this.myDepartment=new Department(); return myDepartment; } public void setMydepartment(Department mydepartment) { this.myDepartment = mydepartment; } /** * 获取所有部门员工信息 * @param myStaff 姓名 工号 年龄 性别 * @param myDepartment 人事部 市场部 * @param myPosition 经理 助理 职员 * @return 姓名 工号 年龄 性别 部门 职务 */ public String neirong(Department myDepartment,Position myPosition) { String str="姓名:" + this.getName() + "\n工号:" + this.getJobNumber() + "\n性别:" + this.getGender() + "\n年龄:"+this.getAge()+"\n职务:"+myDepartment.getName()+myPosition.getzhiwei(); return str; } }
package operation; /** * 测试类 * @author ThinkPad */ public class Test { public static void main(String[] args) { Department bumen1=new Department("人事部"); Department bumen2=new Department("市场部"); Position zhiwei1=new Position("经理"); Position zhiwei2=new Position("助理"); Position zhiwei3=new Position("职员"); Staff one=new Staff("张铭","S001",29,"男"); System.out.println(one.neirong(bumen1, zhiwei1)); System.out.println("============================="); Staff two=new Staff("李艾爱","S002",21,"女"); System.out.println(two.neirong(bumen1,zhiwei2)); System.out.println("============================="); Staff three=new Staff("孙超","S004",29,"男"); System.out.println(three.neirong(bumen1,zhiwei3)); System.out.println("============================="); Staff four=new Staff("张美美","S005",26,"女"); System.out.println(four.neirong(bumen2,zhiwei3)); System.out.println("============================="); Staff fives=new Staff("蓝迪","S006",37,"男"); System.out.println(fives.neirong(bumen2,zhiwei1)); System.out.println("============================="); Staff six=new Staff("米莉","S007",24,"女"); System.out.println(six.neirong(bumen2,zhiwei3)); System.out.println("============================="); bumen1.addStaff(one); bumen1.addStaff(two); bumen1.addStaff(three); bumen2.addStaff(four); bumen2.addStaff(fives); bumen2.addStaff(six); System.out.println(bumen1.getName()+"总共有"+bumen1.getStaffNum()+"名员工。"); System.out.println(bumen2.getName()+"总共有"+bumen2.getStaffNum()+"名员工。"); } }
0
收起
正在回答
1回答
同学你好,根据作业要求,部门要有部门编号,职务要有职务编号,同学的这些类中都没有添加,建议加上。另外在员工中,应该有职务属性用来描述员工所属职务,在对性别进行判断时,建议同学使用equals来比较字符串进行更有效的判断。最后建议同学将作业打包交上来,方便我们老师针对同学的作业给出具体的意见。
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星