Free Essay

Cis247 Week 4 Lab

In:

Submitted By monjiques
Words 335
Pages 2
class Employee { //Data members protected string firstName; protected string lastName; protected char gender; protected int dependents; protected double annualSalary; protected Benefits benefit; protected string employeeType;

protected static int numEmployees = 0;

//Constants public const string DEFAULT_Name = "not given"; public const int MIN_DEPENDENTS = 0; public const int MAX_DEPENDENTS = 10; public const double MIN_SALARY = 20000; public const double MAX_SALARY = 100000; public const char DEFAULT_Gender = 'U'; public const int DEFAULT_Dependents = 0; public const string DEFAULT_EmployeeType = "not given";

#region Constructors

// Default Constructor public Employee () { firstName = DEFAULT_Name; lastName = DEFAULT_Name; gender = DEFAULT_Gender; dependents = DEFAULT_Dependents; annualSalary = MIN_SALARY; employeeType = DEFAULT_EmployeeType;

benefit = new Benefits();

numEmployees++; }

//Overloaded Constructors public Employee(string firstName, string lastName, char gender, int dependents, double annualSalary, Benefits benefit, string employeeType) { //Restricitons applied to data members through using the properties instead of the data members this.FirstName = firstName; this.LastName = lastName; this.Gender = gender; this.Dependents = dependents; this.AnnualSalary = annualSalary;

Benefit = benefit;

numEmployees++; }

public Employee(string employeeType) :this() { }

#endregion

#region Properties

public String EmployeeType { get { return employeeType; } }

public Benefits Benefit { get { return benefit; } set { if (value == null) benefit = new Benefits(); else benefit = value; } }

public string FirstName { get {return firstName;}

set { //Validating Input: IF null or empty, value assigned to default. //ELSE input is set to the value if (String.IsNullOrEmpty(value)) firstName = DEFAULT_Name; else firstName = value; } }

public string LastName { get { return lastName;}

set { //Validating Input: IF null or empty, value assigned to default //ELSE input is set to the value if (String.IsNullOrEmpty(value)) lastName = DEFAULT_Name; else lastName = value; } } public char Gender { get { return gender; } set {//If the gender value is 'F', 'f', 'M', or 'm' set the value; othe ||rwise set the value to DEFAULT_GENDER.

if (value == 'f' || value == 'F' || value == 'M' || value == 'm') gender = value; else gender = DEFAULT_Gender; } }

public int Dependents { get { return dependents; }

set { /*If dependent value is between the MIN_DEPENDENTS and MAX_DEPENDENTS (inclusive) then the dependent to the value; *If the value is less than MIN_DEPENDENTS then the dependents set to MIN_DEPENDENTS; *Else if value is greater than MAX_DEPENDENTS then the dependents set to MAX_DEPENDENTS.*/ if (value >= MIN_DEPENDENTS && value = MIN_SALARY && value

Similar Documents

Premium Essay

Cis247C Lab5

...// 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,...

Words: 813 - Pages: 4