⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employee.java

📁 JAVA编程百例书中各章节的所有例子的源代码,包括套接字编程
💻 JAVA
字号:
package ch10.section08;

import java.util.*;

public class Employee {
  String name;
  float salary;
  Vector subordinates;
  boolean isLeaf;
  Employee parent = null;

  public Employee(String _name, float _salary) {
    name = _name;
    salary = _salary;
    subordinates = new Vector();
    isLeaf = false;
  }

  public Employee(Employee _parent, String _name, float _salary) {
    name = _name;
    salary = _salary;
    parent = _parent;
    subordinates = new Vector();
    isLeaf = false;
  }

  public void setLeaf(boolean b) {
    isLeaf = b;
  }

  public float getSalary() {
    return salary;
  }

  public String getName() {
    return name;
  }

  public boolean add(Employee e) {
    if (!isLeaf) {
      subordinates.addElement(e);
    }
    return isLeaf;
  }

  public void remove(Employee e) {
    if (!isLeaf) {
      subordinates.removeElement(e);
    }
  }

  public Enumeration elements() {
    return subordinates.elements();
  }

  public Employee getChild(String s) {
    Employee newEmp = null;

    if (getName().equals(s)) {
      return this;
    }
    else {
      boolean found = false;
      Enumeration e = elements();
      while (e.hasMoreElements() && (!found)) {
        newEmp = (Employee) e.nextElement();
        found = newEmp.getName().equals(s);
        if (!found) {
          newEmp = newEmp.getChild(s);
          found = (newEmp != null);
        }
      }
      if (found) {
        return newEmp;
      }
      else {
        return null;
      }
    }
  }

  public float getSalaries() {
    float sum = salary;
    for (int i = 0; i < subordinates.size(); i++) {
      sum += ( (Employee) subordinates.elementAt(i)).getSalaries();
    }
    return sum;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -