Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Exam_Preparation1
- {
- public class Company
- {
- private string name;
- private List<Employee> employees;
- public Company(string name)
- {
- Name = name;
- employees = new List<Employee>();
- }
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- if (value.Length < 3)
- {
- throw ArgumentException("Invalid name");
- }
- name = value;
- }
- }
- private Exception ArgumentException(string v)
- {
- throw new NotImplementedException();
- }
- public List<Employee> Employees
- {
- get
- {
- return employees;
- }
- set
- {
- employees = value;
- }
- }
- public override string ToString()
- {
- string result = "";
- if (employees.Count <= 0)
- {
- result += $"Company {name} has 0 employees and they are:\n";
- result += "N/A";
- }
- else
- {
- result += $"Company {name} has {employees.Count} employees and they are:\n";
- foreach(Employee employee in employees)
- {
- result += employee.ToString() + "\n";
- }
- }
- return result;
- }
- public void Hire(Employee employee)
- {
- employees.Add(employee);
- }
- public bool Fire(Employee employee)
- {
- return employees.Remove(employee);
- }
- public double CalculateSalaries()
- {
- //return employees.Sum(employee => employee.Salary);
- double totalSalaries = 0;
- foreach(Employee employee in employees)
- {
- totalSalaries += employee.Salary;
- }
- return totalSalaries;
- }
- public Employee GetEmployeeWithHighestSalary()
- {
- return employees.OrderByDescending(emp => emp.Salary).First();
- }
- public bool CheckEmployeeIsHired(string name)
- {
- foreach(Employee employee in employees)
- {
- if (name == employee.Name)
- {
- return true;
- }
- }
- return false;
- }
- public void RenameCompany(string newName)
- {
- Name = newName;
- }
- public void FireAllEmployees()
- {
- employees.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement