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

            SalaryWorker    mickeyMouse = new SalaryWorker(400000, "Mouse", "Mickey");
            HourlyWorker    minnieMouse = new HourlyWorker(30, "Mouse", "Minnie");
            VolunteerWorker donaldDuck  = new VolunteerWorker("Duck", "Donald");
            HourlyWorker    georgeGeff  = new HourlyWorker(15, "Geef", "George (Goofy)");

            List <IWorker> workers = new List <IWorker>();

            workers.Add(mickeyMouse);
            workers.Add(georgeGeff);
            workers.Add(minnieMouse);
            workers.Add(donaldDuck);

            Console.WriteLine("Employee".PadRight(30) + "Hours Worked".PadRight(30) + "Pay");

            int    totalHours = 0;
            double totalPay   = 0;

            foreach (IWorker worker in workers)
            {
                string fullName = worker.FirstName + ", " + worker.LastName;
                int    hours    = randomHoursWorked.Next(0, 168);
                Console.WriteLine(fullName.ToString().PadRight(30) + hours.ToString().PadRight(30) + worker.CalculateWeeklyPay(hours).ToString("C"));
                totalHours += hours;
                totalPay   += worker.CalculateWeeklyPay(hours);
            }

            Console.WriteLine();
            Console.WriteLine($"Total Hours: {totalHours}");
            Console.WriteLine($"Total Pay: {totalPay.ToString("C")}");
            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Random          rnd     = new Random();
            List <IWorker>  workers = new List <IWorker>();
            SalaryWorker    ally    = new SalaryWorker(70000, "Ally", "Hurt");
            SalaryWorker    eli     = new SalaryWorker(100000, "Eli", "Reynolds");
            HourlyWorker    tom     = new HourlyWorker(20.00, "Tom", "Ploetz");
            HourlyWorker    dan     = new HourlyWorker(50.00, "Dan", "Ridell");
            VolunteerWorker austin  = new VolunteerWorker("Austin", "De");
            VolunteerWorker jon     = new VolunteerWorker("Jon", "Bedell");


            int totalHours = 0;
            int totalPay   = 0;

            workers.Add(ally);
            workers.Add(tom);
            workers.Add(austin);
            workers.Add(eli);
            workers.Add(jon);
            workers.Add(dan);


            Console.WriteLine("Employee \t Hours Worked \t Pay");
            foreach (var worker in workers)
            {
                int hoursWorked = rnd.Next(1, 50);
                totalHours += hoursWorked;
                Console.WriteLine(worker.LastName + ", " + worker.FirstName + " \t " + hoursWorked + "\t" + "\t" + " " + worker.CalculateWeeklyPay(hoursWorked).ToString("c"));
                totalPay += (int)worker.CalculateWeeklyPay(hoursWorked);
            }
            Console.WriteLine();
            Console.WriteLine("Total hours worked: " + totalHours);
            Console.WriteLine("Total pay: " + totalPay.ToString("c"));

            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            List <IWorker>  AllWorkers = new List <IWorker>();
            HourlyWorker    Hourly     = new HourlyWorker(20, "John", "Doe", 40);
            SalaryWorker    Salary     = new SalaryWorker(40, "Jane", "Doe", 40);
            VolunteerWorker Volunteer  = new VolunteerWorker("Steve", "Jobs", 44);

            AllWorkers.Add(Hourly);
            AllWorkers.Add(Salary);
            AllWorkers.Add(Volunteer);
            Console.WriteLine($"Employee".PadRight(15) + "Hours".PadRight(12) + "Pay".PadRight(10));
            int    totalHours = 0;
            double totalPay   = 0;

            foreach (IWorker Worker in AllWorkers)
            {
                Console.WriteLine($"{Worker.FirstName} {Worker.LastName.PadRight(10)} {Worker.HoursWorked.ToString().PadRight(10)} {Worker.CalculateWeeklyPay(Worker.HoursWorked).ToString().PadRight(10)}");
                totalHours += Worker.HoursWorked;
                totalPay   += Worker.CalculateWeeklyPay(Worker.HoursWorked);
            }

            Console.WriteLine($"Total Hours : {totalHours}");
            Console.WriteLine($"Total Pay : {totalPay.ToString("$0.00")}");
        }