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

📄 manager.java

📁 ssd3部分quiz、exercise、exam的参考答案
💻 JAVA
字号:
import java.util.*;

public class Manager implements Employee{
	String ID;
	String name;
	double salary;
	ArrayList<Employee> subordinates = new ArrayList<Employee>();
	
	public Manager(String initialId, String initialName, double initialSalary) {
		this.ID = initialId;
		this.name = initialName;
		this.salary = initialSalary;
	}
	
	public String getId() {
		return this.ID;
	}
	
	public String getName() {
		return this.name;
	}
	
	public double getSalary() {
		return this.salary;
	}
	
	public String getEmployeeType() {
		return "Manager";
	}
	
	public boolean equals(Object object) {
		return (object instanceof Manager) && this.ID == ((Manager)object).getId();
	}
	
	public void addSubordinate(Employee employee) {
		subordinates.add(employee);
	}
	
	public void removeSubordinate(Employee employee) {
		subordinates.remove(employee);		
	}
	
	public Employee getSubordinate(String employeeId) {
		Employee temp = null;
		for(Employee employee: subordinates) {
			if(employee.getId().equals(employeeId)) {
				temp = employee;
				break;
			}
		}
		return temp;
		
	}
	
	public int getNumberOfSubordinates() {
		return subordinates.size();
	}
	
	public Employee[] getArrayOfSubordinates() {
		int record = subordinates.size(), i = 0;
		Employee[] recordSwitch = new Employee[record];
		for(Employee employee: subordinates) {
			recordSwitch[i] = employee;
			i++;
		}
		return recordSwitch;
	}
	
	public String getXML() {
		String record = "<manager>\n<id>" + this.ID + "</id>\n<name>" + this.name + "</name>\n<salary>" +
				this.salary + "</salary>";
		
		for(Employee employee: subordinates) {
			record += "\n<subordinate id=\"" + employee.getId() + "\">" + employee.getName() + "</subordinate>";
		}
		record += "</manager>";
		
		return record;
	}
	
	public ArrayList<Employee> getSubordinatesManagers() {
		return this.subordinates;
	}
}

⌨️ 快捷键说明

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