老师 看一下作业的不足之处

老师 看一下作业的不足之处

部门类

package HomeWork;


public class Department {

// 定义部门编号、部门名称、员工数组、统计部门中的员工个数

// number1 number2 输出两个部门

private String Departmentnub;

private String DepartmentName;

private Employees[] myEmployees;

private int number1;

private int number2;

//无参构造

public Department() {

}

//带参构造

public Department(String departmentnub, String departmentName, Employees[] myEmployees, int number1, int number2) {

this.setDepartmentnub(departmentnub);

this.setDepartmentName(departmentName);

this.setMyEmployees(myEmployees);

this.setNumber1(number1);

this.setNumber2(number2);

}


public int getNumber1() {

return number1;

}


public void setNumber1(int number1) {

this.number1 = number1;

}


public int getNumber2() {

return number2;

}


public void setNumber2(int number2) {

this.number2 = number2;

}


public String getDepartmentnub() {

return Departmentnub;

}


public void setDepartmentnub(String departmentnub) {

Departmentnub = departmentnub;

}


public String getDepartmentName() {

return DepartmentName;

}


public void setDepartmentName(String departmentName) {

DepartmentName = departmentName;

}


public Employees[] getMyEmployees() {

if (this.myEmployees == null) {

this.myEmployees = new Employees[20];

}

return myEmployees;

}


public void setMyEmployees(Employees[] myEmployees) {

this.myEmployees = myEmployees;

}


public int getNumber() {

return number1;

}


public void setNumber(int number1) {

this.number1 = number1;

}


/*

* 定义一个方法 循环遍历传入的值 将 Employees类里面的部门保存到数组中

* 如果遍历到的数组位置的成员等于空,说明还没有部门这个值存入进来,判断如果传入的部门为人事部的话 把sc这个值存放进去 并且 number1 自增1

* 反之number2自增1

*/

public void js(Employees sc) {

for (int i = 0; i < this.getMyEmployees().length; i++) {

if (this.getMyEmployees()[i] == null) {

if (sc.getEmployeesBM() == "人事部") {

this.getMyEmployees()[i] = sc;

this.number1 = i + 1;

return;

} else {

this.number2 += 1;

return;

}

}

}

}

}

==========================================================

职务类

package HomeWork;

     //职务类

public class Duties {

//描述职务编号、职务名称

private String DutiesNub;

private String DutiesName;

public Duties() {

}


public Duties(String dutiesNub, String dutiesName) {

this.setDutiesNub(dutiesNub);

this.setDutiesName(dutiesName);

}


public String getDutiesNub() {

return DutiesNub;

}


public void setDutiesNub(String dutiesNub) {

DutiesNub = dutiesNub;

}


public String getDutiesName() {

return DutiesName;

}


public void setDutiesName(String dutiesName) {

DutiesName = dutiesName;

}

//定义一个方法输出

public void sc() {

System.out.println("职务编号:"+this.getDutiesNub()+"\n职务名称"+this.getDutiesName());

}

}

======================================================

员工类

package HomeWork;


public class Employees {

// 员工属性:员工姓名、工号、年龄、性别、所属部门、职务信息

private String EmployeesName;

private String EmployeesNumber;

private char EmployeesSex;

private int EmployeesAge;

private String EmployeesBM;

private String EmployeesZW;


// 无参构造

public Employees() {


}


public Employees(String employeesName, String employeesNumber, char employeesSex,int employeesAge, 

String employeesBM, String employeesZW) {

this.setEmployeesName(employeesName);

this.setEmployeesNumber(employeesNumber);

this.setEmployeesAge(employeesAge);

this.setEmployeesSex(employeesSex);

this.setEmployeesBM(employeesBM);

this.setEmployeesZW(employeesZW);

}


public String getEmployeesName() {

return EmployeesName;

}


public void setEmployeesName(String employeesName) {

EmployeesName = employeesName;

}


public String getEmployeesNumber() {

return EmployeesNumber;

}


public void setEmployeesNumber(String employeesNumber) {

EmployeesNumber = employeesNumber;

}


public int getEmployeesAge() {

return EmployeesAge;

}

//设定方法限定年龄只能是18--65之间,反之则设置默认为18岁

public void setEmployeesAge(int employeesAge) {

if (employeesAge > 17 & employeesAge < 66) {

EmployeesAge=employeesAge;

} else {

this.EmployeesAge=18;

}

}


public char getEmployeesSex() {

return EmployeesSex;

}

// 设定方法限定性别只能是“男”或者“女”,反之则设置默认为"男"

public void setEmployeesSex(char employeesSex) {

if (employeesSex == '男' | employeesSex == '女') {

EmployeesSex = employeesSex;

} else {

this.EmployeesSex='男';

}

}


public String getEmployeesBM() {

return EmployeesBM;

}


public void setEmployeesBM(String employeesBM) {

EmployeesBM = employeesBM;

}


public String getEmployeesZW() {

return EmployeesZW;

}


public void setEmployeesZW(String employeesZW) {

EmployeesZW = employeesZW;

}

// 设定方法,实现员工自我介绍信息,将员工信息作为字符串返回

public String JieShao() {

String str = "姓名:" + this.getEmployeesName() + "\n工号:" + this.getEmployeesNumber() + "\n性别:"

+ this.getEmployeesSex() + "\n年龄:" + this.getEmployeesAge() + "\n职务:" + this.getEmployeesBM()

+ this.getEmployeesZW();

return str;

}

}

=========================================================

测试

package HomeWork;


public class Text {

public static void main(String[] args) {

Employees one = new Employees("张铭", "S001", '男', 29, "人事部", "经理");

System.out.println(one.JieShao());

System.out.println("=========================");

Employees two = new Employees("李艾爱", "S002", '女', 21, "人事部", "助理");

System.out.println(two.JieShao());

System.out.println("=========================");

Employees three = new Employees("孙超", "S004", '男', 29, "人事部", "职员");

System.out.println(three.JieShao());

System.out.println("=========================");

Employees four = new Employees("张美美", "S005", '女', 26, "市场部", "职员");

System.out.println(four.JieShao());

System.out.println("=========================");

Employees five = new Employees("蓝迪", "S006", '男', 37, "市场部", "经理");

System.out.println(five.JieShao());

System.out.println("=========================");

Employees six = new Employees("米莉", "S007", '女', 24, "市场部", "职员");

System.out.println(six.JieShao());

Department sc=new Department(); //调用方法 依次传入部门

sc.js(one);

sc.js(two);

sc.js(three);

sc.js(four);

sc.js(five);

sc.js(six);

System.out.println("=========================");

System.out.println(one.getEmployeesBM()+"总共有"+sc.getNumber1()+"名员工");

System.out.println(four.getEmployeesBM()+"总共有"+sc.getNumber2()+"名员工");

}

}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕珊 2020-03-14 15:32:17

同学,你好!作业中的问题及修改建议如下:

1、包名不符合命名规范,应该所有字母均小写

2、Department类,不需要两个变量分别统计人事部和市场部的人数,在统计时也不需要判断。保留一个变量做数据统计就可以了,具体是市场部还是人事部是通过定义对象来展现的。如果定义的是市场部的对象,那么这些属性就都属于市场部,反之如果定义的是人事部的对象,这些属性也都属于人事部。

3、Employees类,部门和职务应改为Department和Duties类的对象,而不是定义字符串。使用对象可以方便进一步获取该对象的其他属性。注意与之对应的其他方法也需要更改

4、测试类中,应该分别定义两个部门的对象,然后将员工对象分别添加到两个部门中。

5、&和|运算符可以改成短路运算符&&和||,这样效率更高

建议同学再看看封装案例的内容,改完后可以提交作业,我们的老师会进行批改。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 何猪猪 #1
    老师 定义一个变量做统计 那最后输出的是两个结果啊 总不能两个输出结果输出的都是一个对象吧
    2020-03-15 10:28:40
  • 好帮手慕珊 回复 提问者 何猪猪 #2
    同学,你好!测试类中要定义两个部门对象,两个对象分别调用方法去添加员工,然后分别调用getNumber()方法输出统计数据。祝学习愉快!
    2020-03-15 12:08:17
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师