/// <summary> /// Moves an Executive out of the current department, into a new department /// </summary> /// <param name="executive"></param> /// <param name="department"></param> public void Change(Executive executive, Department department) { //remove executive from current department this.Quit(executive); //add exectuvie to target department department.Join(executive); }
/// <summary> /// Adds a new Executive to the Queue. /// </summary> /// <remarks>Updates payroll.</remarks> /// <param name="executive"></param> public void Join(Executive executive) { //add new executive to end of queue Executives.Enqueue(executive); //update payroll Payroll(); }
/// <summary> /// Finds an Exeuctive by their ExecutiveID and removes them from the Queue. /// If a match is not found, no error occurs. The queue is simply unchanged. /// </summary> /// <remarks>Updates payroll.</remarks> /// <param name="executive"></param> public void Quit(Executive executive) { //number of elements in queue int count = Executives.Count; int salary = SALARY_RATE * count; //evaluate every element in the queue for (int i = 0; i < count; i++) { //remove the first item in the queue Executive current = Executives.Dequeue(); //if not a match, return the item to the end of the queue if (current.EmployeeID != executive.EmployeeID) { salary -= SALARY_RATE; current.Salary = salary; Executives.Enqueue(current); } //if a match is found, the item will not be returned to the queue, thus removing it permanently } //when the loop finishes, all elements will be correctly ordered with accurate salary }