You are tasked with managing a list of employees with the following details: ID, Name, Age, and Salary. Implement a Manager struct that provides the following functionalities:
- AddEmployee: Add a new employee to the list.
- RemoveEmployee: Remove an employee based on their ID.
- GetAverageSalary: Calculate the average salary of all employees.
- FindEmployeeByID: Retrieve an employee's details by their ID.
Define the following structures:
type Employee struct {
ID int
Name string
Age int
Salary float64
}
type Manager struct {
Employees []Employee
}Implement the following methods:
func (m *Manager) AddEmployee(e Employee)
func (m *Manager) RemoveEmployee(id int)
func (m *Manager) GetAverageSalary() float64
func (m *Manager) FindEmployeeByID(id int) *Employee- Fork the repository and clone your fork.
- Create your submission directory inside
challenge-3/submissions/. - Copy the
solution-template.gofile into your submission directory. - Implement and test your solution using the test file.
- Submit your solution by creating a pull request.
manager := Manager{}
manager.AddEmployee(Employee{ID: 1, Name: "Alice", Age: 30, Salary: 70000})
manager.AddEmployee(Employee{ID: 2, Name: "Bob", Age: 25, Salary: 65000})
manager.RemoveEmployee(1)
averageSalary := manager.GetAverageSalary()
employee := manager.FindEmployeeByID(2)Run the following command in the challenge-3 directory:
go test -v