Free Essay

Cis247A Week 3

In:

Submitted By onesickjdmbb6
Words 415
Pages 2
using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace CIS247_Week3ilabrevised_JohnDoe
//John Doe
//CIS 247A Week 3 iLab
//Employee Class Program
{
class Employee
{
private string firstName; private string lastName; private char gender; private int dependents; private double annualSalary; private double pay; public static int numEmployees = 0;

public const string DEFAULT_FIRST = " not given"; public const string DEFAULT_LAST = " not given"; public const char DEFAULT_GENDER = 'U'; public const int DEFAULT_DEPENDENTS = 0; private const double DEFAULT_ANNUALSALARY = 20000;

public Employee()
{
FirstName = DEFAULT_FIRST; LastName = DEFAULT_LAST; Gender = DEFAULT_GENDER; Dependents = DEFAULT_DEPENDENTS; AnnualSalary = DEFAULT_ANNUALSALARY; numEmployees++;
}

public Employee(string first, string last, char gen, int dep, double salary)
{

firstName = first; lastName = last; gender = gen; annualSalary = salary; numEmployees++;

}

public string FirstName
{
get
{ return firstName; } set {firstName = value;}
}
public string LastName
{
get
{ return lastName; } set {lastName = value;}
}
public char Gender
{
get
{ return gender; } set {gender = value;}

} public int Dependents
{
get
{ return dependents; } set { dependents = value;}
}

public double AnnualSalary
{
get { return annualSalary; } set { if(value > 19999) annualSalary = value; else annualSalary = DEFAULT_ANNUALSALARY;
}
} public static int GetNumEmployees()
{
return numEmployees;
}
public double CalculatePay()
{
return (annualSalary / 52);

} public override string ToString()
{
string str;

str = "Employee AnnualSalary: $" + AnnualSalary.ToString("N2") + "\n "; return str;
}
public void DisplayEmployeeInformation(string first, string last, char gen, int dep, double salary)
{

Console.WriteLine("First Name: " + first);
Console.WriteLine("Last Name: " + last);
Console.WriteLine("Gender: " + gen);
Console.WriteLine("Dependents: " + dep);
Console.WriteLine("Annual Salary:$ " + salary.ToString("N2")); annualSalary = salary; pay = CalculatePay();
Console.WriteLine("Employee Weekly Pay:$ " + pay.ToString("N2"));
Console.WriteLine("Total Employees:" + numEmployees);
}

public void DisplayEmployee()
{
Console.WriteLine("First Name: " + FirstName); Console.WriteLine("Last Name: " + LastName); Console.WriteLine("Gender: " + Gender); Console.WriteLine("Dependents: " + Dependents); double tempSalary = AnnualSalary; Console.WriteLine("Annual Salary: $" + tempSalary.ToString("N2")); pay = CalculatePay(); Console.WriteLine("Employee Weekly Pay: $" + pay.ToString("N2")); Console.WriteLine("Total Employees: " + Employee.GetNumEmployees());
}

}

namespace Help
{
public class Program
{
static void Main(string[] args)
{

DisplayApplicationInformation();
DisplayDivider("Start Program");

Employee employee1 = new Employee(); employee1.FirstName = GetInput("First Name"); employee1.LastName = GetInput("Last Name"); employee1.Gender = char.Parse(GetInput("Gender")); employee1.Dependents = int.Parse(GetInput("Dependents")); employee1.AnnualSalary = double.Parse(GetInput("Salary"));
DisplayDivider("Employee Information"); employee1.DisplayEmployee(); DisplayDivider("Employee Information");

Employee employee2 = new Employee("Mary", "Nola", 'F', 5, 24000.0);

employee2.DisplayEmployee();

Console.ReadLine();

} private static void DisplayApplicationInformation()
{
Console.WriteLine("Employee Class Program");
Console.WriteLine("CIS247, Week 3 iLab");
Console.WriteLine("John Doe");
Console.WriteLine("This program will increment the employee class to count the employees");
Console.WriteLine();
}

private static void DisplayDivider(string outputTitle)
{
Console.WriteLine("***************" + outputTitle + " " + "***************");
}

private static string GetInput(string inputType)
{
string strInput = String.Empty;
Console.Write(" Please enter " + inputType + " : "); strInput = Console.ReadLine();

return strInput;
}

}
}
}

Similar Documents