static void Main(string[] args) { //NUMERO DE FUNCIONARIOS Console.Write("How many employees will be registered? "); int n = int.Parse(Console.ReadLine()); //REGISTRAR FUNCIONARIOS int cont = 1; List <Employee> list = new List <Employee>(); for (int i = 0; i < n; i++) { Console.WriteLine("Emplyoee #" + cont); cont++; //ACRESCENTANDO PARA O PRÓXIMO FUNCIONARIO. Console.Write("Id: "); int id = int.Parse(Console.ReadLine()); Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Salary: "); double salary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); Console.WriteLine(); list.Add(new Employee(id, name, salary));//ADICIONANDO OS ATRIBUTOS NA LISTA. } Console.Write("Enter the employee id that will have salary increase: ");//PEGANDO ID DO FUNCIONARIO. int _id = int.Parse(Console.ReadLine()); Employee emp = list.Find(x => x.Id == _id);//PROCURANDO O ELEMENTO NA LISTA if (emp != null) { Console.Write("Enter the porcentage: "); double percentage = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); emp.IncreaseSalary(percentage); } else { Console.WriteLine("This id does not exist!"); } Console.WriteLine(); Console.WriteLine("Update list of employees:"); foreach (Employee obj in list) { Console.WriteLine(obj); } }
public static void Main(string [] args) { Employee Andrew = new Employee("Andrew", "Connelly", 2000.00M); Employee Rebecca = new Employee("Rebecca", "Connelly", 1600.00M); decimal salaryIncreaseAndrew = Andrew.IncreaseSalary(Andrew.MonthlySalary); decimal salaryIncreaseRebecca = Rebecca.IncreaseSalary(Rebecca.MonthlySalary); decimal annualSalaryAndrew = Andrew.AnnualSalary(Andrew.MonthlySalary); decimal annualSalaryRebecca = Rebecca.AnnualSalary(Rebecca.MonthlySalary); Console.WriteLine("Andrew's monthly salary after increase is: {0:C}, his annual salary is: {1:C}", salaryIncreaseAndrew, annualSalaryAndrew); Console.WriteLine("Rebecca's monthly salary after increase is: {0:C}, her annual salary is: {1:C}", salaryIncreaseRebecca, annualSalaryRebecca); Console.ReadKey(); } //end main method