Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace StructConsole
- {
- class Worker
- {
- private string Name;
- private int Year;
- private byte Month;
- public Worker()
- {
- Name = "Trener V. J.";
- Year = DateTime.Now.Year;
- Month = (byte)DateTime.Now.Month;
- }
- public Worker(string name, int year, byte month)
- {
- SetName(name);
- SetYear(year);
- SetMonth(month);
- }
- public Worker(string name, int year)
- {
- SetName(name);
- SetYear(year);
- SetMonth((byte)DateTime.Now.Month);
- }
- public Worker(Worker copy)
- {
- Name = copy.Name;
- Year = copy.Year;
- Month = copy.Month;
- }
- public void SetName(string name)
- {
- if(name.Length > 0)
- Name = name;
- }
- public void SetYear(int year)
- {
- if (year > 2000 && year < 2019)
- Year = year;
- }
- public void SetMonth(byte month)
- {
- if (month > 0 && month < 13)
- Month = month;
- }
- public string GetName()
- {
- return Name;
- }
- public int GetYear()
- {
- return Year;
- }
- public byte GetMonth()
- {
- return Month;
- }
- }
- class Company
- {
- private string Name;
- private string Position;
- private int Salary;
- public Worker NewWorker;
- public Company()
- {
- Name = "Valve";
- Position = "Cashhunter";
- Salary = 1234567;
- }
- public Company(string position, int salary)
- {
- Name = "Valve";
- Position = position;
- Salary = salary;
- }
- public Company(string name, string position, int salary)
- {
- Name = name;
- Position = position;
- Salary = salary;
- }
- public Company(Company copy)
- {
- Name = copy.Name;
- Position = copy.Position;
- Salary = copy.Salary;
- }
- public void SetName(string name)
- {
- if(name.Length > 0)
- Name = name;
- }
- public void SetPosition(string position)
- {
- if(position.Length > 0)
- Position = position;
- }
- public void SetSalary(int salary)
- {
- if (salary > 0 && int.TryParse(Console.ReadLine(), out salary))
- Salary = salary;
- else
- Console.WriteLine("Enter another value!");
- }
- public string GetName()
- {
- return Name;
- }
- public string GetPosition()
- {
- return Position;
- }
- public int GetSalary()
- {
- return Salary;
- }
- public void SetWorker(string name, int year, byte month)
- {
- NewWorker.SetName(name);
- NewWorker.SetYear(year);
- NewWorker.SetYear(month);
- }
- public int GetWorkExperience(Company copy)
- {
- DateTime YourYear = new DateTime(copy.NewWorker.GetYear());
- DateTime Today = new DateTime(DateTime.Now.Year);
- int res = Convert.ToInt32((Today - YourYear));
- return res / 12;
- }
- public int GetTotalMoney(Company copy)
- {
- return copy.GetSalary() * NewWorker.GetMonth();
- }
- }
- class Program
- {
- static void StopMech()
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Press enter to continue...");
- Console.ReadKey();
- }
- static void CheckInputData(out int n, string phrase)
- {
- bool flag = true;
- do
- {
- Console.Write(phrase);
- if(!Int32.TryParse(Console.ReadLine(), out n))
- {
- flag = false;
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine("Error404. Try to enter again!");
- }
- } while (!flag);
- }
- public static Worker[] ReadAllWorkers()
- {
- int len;
- string lenPhrase = "Enter worker's amount: ";
- CheckInputData(out len, lenPhrase);
- Worker[] workers = new Worker[len];
- for (int i = 0; i < workers.Length; i++)
- {
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- Console.WriteLine("~ ~ ~ ~ WORKER #{0} ~ ~ ~ ~", i + 1);
- workers[i] = ReadWorker();
- }
- return workers;
- }
- public static Worker ReadWorker()
- {
- Worker worker = new Worker();
- Console.Write("Enter worker's surname and initials: ");
- worker.SetName(Console.ReadLine());
- int year;
- string yearPhrase = "Enter worker's experience (years): ";
- CheckInputData(out year, yearPhrase);
- worker.SetYear(year);
- //worker.SetYear(Convert.ToInt32(Console.ReadLine()));
- int month;
- string monthPhrase = "Enter the month worker started working: ";
- CheckInputData(out month, monthPhrase);
- worker.SetMonth((byte)month);
- ReadCompany();
- return worker;
- }
- public static Company ReadCompany()
- {
- Company company = new Company();
- Console.ForegroundColor = ConsoleColor.DarkBlue;
- Console.Write("Enter company name: ");
- company.SetName(Console.ReadLine());
- Console.Write("Enter worker's position in company: ");
- company.SetPosition(Console.ReadLine());
- int salary;
- string salaryPhrase = "Enter worker's salary: ";
- CheckInputData(out salary, salaryPhrase);
- return company;
- }
- public static void PrintCompany(Company company)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Company: ");
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- company.GetName();
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Position: ");
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- company.GetPosition();
- Console.Write("Salary: ");
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- company.GetSalary();
- }
- public static void PrintWorker(Worker worker)
- {
- Company company = new Company();
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write("Worker's name: ");
- Console.ForegroundColor = ConsoleColor.Blue;
- worker.GetName();
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write("Worker's experience: ");
- Console.ForegroundColor = ConsoleColor.Blue;
- worker.GetYear();
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.Write("Worker works since: ");
- Console.ForegroundColor = ConsoleColor.Blue;
- worker.GetMonth();
- PrintCompany(company);
- }
- public static void PrintWorkers(Worker[] workers)
- {
- for (int i = 0; i < workers.Length; i++)
- {
- Console.WriteLine("- - - - WORKER #{0} - - - -", i + 1);
- PrintWorker(workers[i]);
- }
- StopMech();
- }
- public void GetWorkersInfo(Worker[] workers, out int highest, out int lowest)
- {
- Console.Clear();
- int highest = int.MinValue, lowest = int.MaxValue;
- for (int i = 0; i < workers.Length; i++)
- {
- if()
- }
- }
- public int SortWorkersBySalary(Worker a, Worker b)
- {
- Company company = new Company();
- double avgB = company.GetWorkExperience(company);
- double avgA = company.GetWorkExperience(company);
- if (avgA > avgB)
- return 1;
- if (avgA < avgB)
- return -1;
- return 0;
- }
- public int SortWorkersByExperience(Worker a, Worker b)
- {
- DateTime fstDateA = new DateTime(a.GetYear());
- DateTime sndDateB = new DateTime(b.GetYear());
- return DateTime.Compare(fstDateA, sndDateB);
- }
- static void Menu()
- {
- Console.Title = "Лабораторна робота №5";
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("~ ~ ~ ~ MENU ~ ~ ~ ~");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("1. Add workers;\n2. Show all workers;\n3. Show the HIGHEST and LOWEST salaries;\n4. Sort workers by SALARY;\n5. Sort workers by EXPERIENCE");
- }
- static void Main(string[] args)
- {
- ConsoleKeyInfo hotKey;
- int len = 0; //highest, lowest;
- Worker[] workers = new Worker[len];
- do
- {
- Menu();
- hotKey = Console.ReadKey();
- switch(hotKey.Key)
- {
- case ConsoleKey.D1: // Add worker
- workers = ReadAllWorkers();
- len = workers.Length;
- break;
- case ConsoleKey.D2: // Show all workers
- PrintWorkers(workers);
- break;
- case ConsoleKey.D3: // Show the highest and lowest salary
- break;
- case ConsoleKey.D4: // Sort workers by salary
- break;
- case ConsoleKey.D5: // Sort workers by experience
- break;
- case ConsoleKey.D0:
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("See you later!");
- Environment.Exit(0);
- break;
- }
- } while (true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment