-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
48 lines (43 loc) · 2.27 KB
/
Program.cs
File metadata and controls
48 lines (43 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PayrollSystem
{
class Program
{
static void Main(string[] args)
{
SalariedEmployee salariedEmployee = new SalariedEmployee("John", "Smith", "111-11-1111", 800.00M);
HourlyEmployee hourlyEmployee = new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75M, 40.0M);
CommissionEmployee commissionEmployee = new CommissionEmployee("Sue", "Jones", "333-33-3333", 10000.00M, .06M);
BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000.00M, .04M, 300.00M);
Console.WriteLine("Employees processed individually:\n");
Console.WriteLine("{0}\nearned: {1:C}\n", salariedEmployee, salariedEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n", hourlyEmployee, hourlyEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n", commissionEmployee, commissionEmployee.Earnings());
Console.WriteLine("{0}\nearned: {1:C}\n", basePlusCommissionEmployee, basePlusCommissionEmployee.Earnings());
Employee[] employees = new Employee[4];
employees[0] = salariedEmployee;
employees[1] = hourlyEmployee;
employees[2] = commissionEmployee;
employees[3] = basePlusCommissionEmployee;
foreach (var currentEmployee in employees)
{
Console.WriteLine(currentEmployee);
if (currentEmployee is BasePlusCommissionEmployee)
{
//downcast Employee reference to BasePlusCommissionEmployee reference
BasePlusCommissionEmployee employee = (BasePlusCommissionEmployee)currentEmployee;
employee.BaseSalary *= 1.10M;
Console.WriteLine("new base salary with 10% increase is: {0:C}", employee.BaseSalary);
}
Console.WriteLine("earned{0:C}\n", currentEmployee.Earnings());
}
for (int j = 0; j < employees.Length; j++)
Console.WriteLine("Employee {0} is a {1}", j,employees[j].GetType());
Console.ReadLine();
}
}
}