Premium Essay

Cis247C Lab5

In:

Submitted By JohnQ
Words 813
Pages 4
// Program.cs (main program"
//CIS247C Lab5

using System; class Program { static void Main(string[] args) {
Console.WriteLine("\nWelcome the Employee Hierarchy Program\n");
Console.WriteLine("\n CIS247 Week 5 Lab \n");
Console.WriteLine("\n Name: Solution \n ");
Console.WriteLine("\nThis program tests an Employee inheritance hierarchy\n");

Employee[] emp = new Employee[3];

emp[0] = new Employee("Joe", "Doe", 'M', 1, 10000.0, new Benefit("Partial", 1000, 2));

emp[1] = new Salaried("Zoe", "Likoudis", 'F', 3, 20000.0, new Benefit("Full", 2000, 4), 1);

emp[2] = new Hourly("Kate", "Perry", 'F', 0, 75, 25, new Benefit("Partial", 3000, 8), "part time");

for (int i = 0; i < emp.Length; i++)
{
Console.WriteLine("\n***************** Display Employee's Data *****************\n");
Console.WriteLine(emp[i].ToString());
}

Console.WriteLine("\nTotal number of employees in Database: {0}\n", Employee.GetNumberOfEmployees()); }
}

class Employee
{

protected string firstName; protected string lastName; protected char gender; protected int dependents; protected double annualSalary;

private static int numEmployees = 0;

protected Benefit benefit;

public Employee()
{
firstName = "not given"; lastName = "not given"; gender = 'U'; dependents = 0; annualSalary = 20000;

numEmployees++; benefit = new Benefit("not given", 0, 0);
}

public Employee(string first, string last, char gen, int dep, double salary, Benefit benefit)
{
firstName = first; lastName = last; gender = gen; dependents = dep; annualSalary = salary;

numEmployees++; this.benefit = new Benefit(benefit.GetHealthInsurance(), benefit.GetLifeInsurance(), benefit.GetVacation());
}
public virtual double CalculatePay()
{
return annualSalary / 52;
}
public override string ToString()
{
return string.Format("Employee Type\t:

Similar Documents