Esempio n. 1
0
        static void Main(string[] args)
        {
            Payroll payroll = new Payroll();

            payroll.Add("Joe Bloggs", 10000);
            payroll.Add("Eva Lu Ator", 47110);
            payroll.Add("Anna", 15000);
            payroll.Add("Bertil", 28000);
            payroll.Add("Cecila", 22500);

            Console.WriteLine("\nMata in anställda, avsluta med tomt namn.");
            while (true)
            {
                Console.WriteLine();

                string name = Util.AskForString("Name: ");
                if (name == "")
                {
                    break;
                }
                int salary = Util.AskForInt("Lön: ");

                payroll.Add(name, salary);
            }


            Console.WriteLine("\nAnställda:");
            int j = 1;

            foreach (Employee employee in payroll.GetEmployees())
            {
                Console.WriteLine(j + ": " + employee);
                j++;
            }

            Console.WriteLine("\nSök efter anställd");
            string   queryName = Util.AskForString("Ange namn: ");
            Employee byName    = payroll.GetEmployeeByName(queryName);

            Console.WriteLine(byName);

            Console.WriteLine("\nLista efter lönenivå");
            int minSalary = Util.AskForInt("Ange lönenivå: ");

            foreach (var employee in payroll.GetEmployeesWithSalary(minSalary))
            {
                Console.WriteLine(employee);
            }
        }
Esempio n. 2
0
        private static void Print()
        {
            //Get a copy of the payroll
            Employee[] employees = payroll.GetEmployees();

            //Loop on all employees in payroll
            foreach (Employee employee in employees)
            {
                //Console.WriteLine() method does a .ToString() on the Employee instance
                Console.WriteLine(employee);

                //Ternary conditional operator
                //Same as if else
                Console.WriteLine(employee.SalaryLevel.Equals(SalaryLevel.Junior) ?
                                  DoJuniorWork() :
                                  DoSeniorWork());
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Payroll payroll = new Payroll();

            payroll.Add("Joe Bloggs", 10000);
            payroll.Add("Eva Lu Ator", 47110);
            payroll.Add("Anna", 15000);
            payroll.Add("Bertil", 28000);
            payroll.Add("Cecila", 22500);

            Console.WriteLine("\nMata in en anställda, avsluta med Namn = Q");

            while (true)
            {
                Console.WriteLine();

                string name = Util.AskForString("Name: ");
                if (name == "Q")
                {
                    break;
                }

                int salary = Util.AskForInt("Salary: ");

                payroll.Add(name, salary);
            }

            Console.WriteLine("\nAnställdda: ");

            int i = 1;

            foreach (Employee employee in payroll.GetEmployees())
            {
                Console.WriteLine($"{i}: {employee}");
            }
        }
Esempio n. 4
0
        //Entry point of application
        static void Main(string[] args)
        {
            //Create a new instance of payroll
            Payroll payroll = new Payroll();

            //Calls Add method on payroll instance with parameters
            //Only for demo purpose to have some data
            payroll.Add("Kalle", 10000);
            payroll.Add("Nisse", 20000);
            payroll.Add("Anna", 25000);
            payroll.Add("Lisa", 14000);

            //Employee kalle = new Employee("Kalle", 20000);
            //string name = kalle.Name;
            //kalle.SetName("Nisse");

            Console.WriteLine("Enter a new employee, Quit with Q");

            //loop until we press Q
            do
            {
                string name = Util.AskForString("Name: ");
                if (name == "Q")
                {
                    break;                          //Break exits the loop
                }
                int salary = Util.AskForInt("Salary: ");

                payroll.Add(name, salary);
            }while (true); //Endless loop

            //Employee[] employees = payroll.GetEmployees();
            //Console.WriteLine(employees[0].Name);
            //employees[0] = null;
            //var emp2 = payroll.GetEmployees();
            //Console.WriteLine(emp2[0].Name);

            //loop on all employees in payroll
            Employee[] emplopyeess = payroll.GetEmployees();
            foreach (Employee emp in emplopyeess)
            {
                //Console.Writeline() method does a .ToString() on every employee in payroll
                Console.WriteLine(emp);

                if (emp.SalaryLevel.Equals(SalaryLevel.Junior))
                {
                    Console.WriteLine(DoJuniorWork());
                }
                if (emp.SalaryLevel.Equals(SalaryLevel.Senior))
                {
                    Console.WriteLine(DoSeniorWork());
                }

                switch (emp.SalaryLevel)
                {
                case SalaryLevel.Junior:
                    Console.WriteLine(DoJuniorWork());
                    break;

                case SalaryLevel.Senior:
                    Console.WriteLine(DoSeniorWork());
                    break;

                default:
                    break;
                }

                Console.WriteLine(emp.SalaryLevel.Equals(SalaryLevel.Junior) ? DoJuniorWork() : DoSeniorWork());


                string workResult =
                    emp.SalaryLevel == SalaryLevel.Junior ?
                    DoJuniorWork()
                    : DoSeniorWork();


                Console.WriteLine();
                Console.WriteLine("-----------------");
            }
        }