Advertisement
desislava_topuzakova

Program.cs

May 9th, 2020
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exam_Preparation1
  6. {
  7.     class Program
  8.     {
  9.         static Dictionary<string, Employee> employees = new Dictionary<string, Employee>();
  10.         static Dictionary<string, Company> companies = new Dictionary<string, Company>();
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.             static void Main(string[] args)
  15.             {
  16.                 string command = Console.ReadLine();
  17.  
  18.                 while ((command = Console.ReadLine()) != "End")
  19.                 {
  20.                     var commandArgs = command.Split(' ').ToArray();
  21.  
  22.                     switch (commandArgs[0])
  23.                     {
  24.                         case "AddEmployee":
  25.                             AddEmployee(commandArgs.Skip(1).ToArray());
  26.                             break;
  27.                         case "CreateCompany":
  28.                             CreateCompany(commandArgs.Skip(1).ToArray());
  29.                             break;
  30.                         case "Hire":
  31.                             Hire(commandArgs.Skip(1).ToArray());
  32.                             break;
  33.                         case "Fire":
  34.                             Fire(commandArgs.Skip(1).ToArray());
  35.                             break;
  36.                         case "CalculateSalaries":
  37.                             CalculateSalaries(commandArgs.Skip(1).ToArray());
  38.                             break;
  39.                         case "GetEmployeeWithHighestSalary":
  40.                             GetEmployeeWithHighestSalary(commandArgs.Skip(1).ToArray());
  41.                             break;
  42.                         case "CheckEmployeeIsHired":
  43.                             CheckEmployeeIsHired(commandArgs.Skip(1).ToArray());
  44.                             break;
  45.                         case "RenameCompany":
  46.                             RenameCompany(commandArgs.Skip(1).ToArray());
  47.                             break;
  48.                         case "FireAllEmployees":
  49.                             FireAllEmployees(commandArgs.Skip(1).ToArray());
  50.                             break;
  51.                         case "EmployeeInfo":
  52.                             EmployeeInfo(commandArgs.Skip(1).ToArray());
  53.                             break;
  54.                         case "CompanyInfo":
  55.                             CompanyInfo(commandArgs.Skip(1).ToArray());
  56.                             break;
  57.                         default:
  58.                             Console.WriteLine("Invalid command!");
  59.                             break;
  60.                     }
  61.                 }
  62.  
  63.             }
  64.  
  65.             static void CompanyInfo(string[] v)
  66.             {
  67.                 string compName = v[0];
  68.  
  69.                 if (!companies.ContainsKey(compName))
  70.                 {
  71.                     Console.WriteLine("Could not get CompanyInfo");
  72.                     return;
  73.                 }
  74.                 Company company = companies[compName];
  75.                 Console.WriteLine(company);
  76.             }
  77.  
  78.             static void EmployeeInfo(string[] v)
  79.             {
  80.                 string empName = v[0];
  81.  
  82.                 if (!employees.ContainsKey(empName))
  83.                 {
  84.                     Console.WriteLine("Could not get EmployeeInfo");
  85.                     return;
  86.                 }
  87.                 Employee employee = employees[empName];
  88.                 Console.WriteLine(employee);
  89.             }
  90.  
  91.             static void FireAllEmployees(string[] v)
  92.             {
  93.                 string compName = v[0];
  94.  
  95.                 if (!companies.ContainsKey(compName))
  96.                 {
  97.                     Console.WriteLine("Could not FireAllEmployees");
  98.                     return;
  99.                 }
  100.                 Company company = companies[compName];
  101.  
  102.                 company.FireAllEmployees();
  103.             }
  104.  
  105.             static void RenameCompany(string[] v)
  106.             {
  107.                 string compName = v[0];
  108.                 string newName = v[1];
  109.  
  110.                 if (!companies.ContainsKey(compName))
  111.                 {
  112.                     Console.WriteLine("Could not RenameCompany");
  113.                     return;
  114.                 }
  115.                 Company company = companies[compName];
  116.  
  117.                 try
  118.                 {
  119.                     company.RenameCompany(newName);
  120.                     companies.Remove(compName);
  121.                     companies.Add(newName, company);
  122.                 }
  123.                 catch (ArgumentException ex)
  124.                 {
  125.                     Console.WriteLine(ex.Message);
  126.                 }
  127.             }
  128.  
  129.             static void CheckEmployeeIsHired(string[] v)
  130.             {
  131.                 string empName = v[0];
  132.                 string compName = v[1];
  133.  
  134.                 if (!companies.ContainsKey(compName))
  135.                 {
  136.                     Console.WriteLine("Could not CheckEmployeeIsHired");
  137.                     return;
  138.                 }
  139.                 Company company = companies[compName];
  140.  
  141.                 if (company.CheckEmployeeIsHired(empName))
  142.                 {
  143.                     Console.WriteLine($"Employee {empName} is hired");
  144.                 }
  145.                 else
  146.                 {
  147.                     Console.WriteLine($"Employee {empName} is NOT hired");
  148.                 }
  149.             }
  150.  
  151.             static void GetEmployeeWithHighestSalary(string[] v)
  152.             {
  153.                 string compName = v[0];
  154.  
  155.                 if (!companies.ContainsKey(compName))
  156.                 {
  157.                     Console.WriteLine("Could not GetEmployeeWithHighestSalary");
  158.                     return;
  159.                 }
  160.                 Company company = companies[compName];
  161.  
  162.                 Console.WriteLine(company.GetEmployeeWithHighestSalary());
  163.             }
  164.  
  165.             static void CalculateSalaries(string[] v)
  166.             {
  167.                 string compName = v[0];
  168.  
  169.                 if (!companies.ContainsKey(compName))
  170.                 {
  171.                     Console.WriteLine("Could not CalculateSalaries");
  172.                     return;
  173.                 }
  174.                 Company company = companies[compName];
  175.  
  176.                 Console.WriteLine(company.CalculateSalaries());
  177.             }
  178.  
  179.             static void Fire(string[] v)
  180.             {
  181.                 string empName = v[0];
  182.                 string compName = v[1];
  183.  
  184.                 if (!companies.ContainsKey(compName) || !employees.ContainsKey(empName))
  185.                 {
  186.                     Console.WriteLine("Could not fire employee");
  187.                     return;
  188.                 }
  189.  
  190.                 Employee emp = employees[empName];
  191.                 Company company = companies[compName];
  192.                 if (company.Fire(emp))
  193.                 {
  194.                     Console.WriteLine($"Fired employee {empName}");
  195.                 }
  196.                 else
  197.                 {
  198.                     Console.WriteLine($"Did not fire employee {empName}");
  199.                 }
  200.             }
  201.  
  202.             static void Hire(string[] v)
  203.             {
  204.                 string empName = v[0];
  205.                 string compName = v[1];
  206.  
  207.                 if (!companies.ContainsKey(compName) || !employees.ContainsKey(empName))
  208.                 {
  209.                     Console.WriteLine("Could not hire employee");
  210.                     return;
  211.                 }
  212.                 Employee emp = employees[empName];
  213.                 Company company = companies[compName];
  214.                 company.Hire(emp);
  215.             }
  216.  
  217.             static void CreateCompany(string[] v)
  218.             {
  219.                 string name = v[0];
  220.  
  221.                 try
  222.                 {
  223.                     Company company = new Company(name);
  224.                     companies.Add(name, company);
  225.                 }
  226.                 catch (ArgumentException ex)
  227.                 {
  228.                     Console.WriteLine(ex.Message);
  229.  
  230.                 }
  231.             }
  232.  
  233.             static void AddEmployee(string[] v)
  234.             {
  235.                 string name = v[0];
  236.                 double salary = double.Parse(v[1]);
  237.  
  238.                 try
  239.                 {
  240.                     Employee employee = new Employee(name, salary);
  241.                     employees.Add(name, employee);
  242.                 }
  243.                 catch (ArgumentException ex)
  244.                 {
  245.                     Console.WriteLine(ex.Message);
  246.                 }
  247.             }
  248.         }
  249.     }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement