Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i L A B O V E R V I E W Scenario and Summary We have two separate goals this wee

ID: 3635130 • Letter: I

Question

i L A B O V E R V I E W
Scenario and Summary



We have two separate goals this week:

We are going to create an abstract Employee class and an abstract CalculatePay() method. The abstract Employee class will prevent a programmer from creating an object based on Employee. Only objects based on Salaried and Hourly will be allowed. The abstract CalculatePay() method in Employee will force the child classes to implement CalculatePay().
We are going to implement Polymorphism and dynamic binding by creating generalized methods that accept generalized Employee objects to collect input, and display information. In the Main method we will pass derived objects of the Employee class into these generalized methods.


Deliverables

Due this week:

Capture the console output window and paste it into a Word Document.
Zip the project folder.
Put the zip file and screenshots (Word document) in the drop box.

i L A B S T E P S
STEP 1: Understand the UML Diagram


Notice in the updated UML diagram, that the Employee class is designated as abstract by having the class name Employee italicized. Also, the CalculatePay method is also italicized, which means that it is a pure virtual function and needs to be implemented in the derived classes.

Explanation / Answer

//Run the prgram using visual studio 2010 csharp

public abstract class Employee
{

//abstract methods

public abstract void calculatePay();
public abstract void CollectEmployeeInformation();
public abstract void DisplayEmployeeInformation();
}

//HourlyEmployee class emplementing abstract Employee class
class HourlyEmployee:Employee
{
string firstName;
string lastName;
char gender;
int noOfdependents;
string healthInsure;
int lifeInsure;
int vacation;
int wage;
int hours;
string cat;
//@override collectEmployeeinformation method
public override void CollectEmployeeInformation()
{
Console.Write(" Enter First Name:");
firstName = Console.ReadLine();
Console.Write(" Enter Second Name:");
lastName = Console.ReadLine();
Console.Write(" Enter gender:");
gender = Char.Parse(Console.ReadLine());
Console.Write(" Enter number of Dependents:");
noOfdependents = Int32.Parse(Console.ReadLine());
Console.Write(" Enter Health insurance:");
healthInsure = Console.ReadLine();
Console.Write(" Enter Life insurance amount:");
lifeInsure = Int32.Parse(Console.ReadLine());
Console.Write(" Enter Number of vacations:$");
vacation = Int32.Parse(Console.ReadLine());
Console.Write(" Enter wage:$");
wage = Int32.Parse(Console.ReadLine());
Console.Write(" Enter Hours:");
hours = Int32.Parse(Console.ReadLine());
Console.Write(" Enter category:");
cat = Console.ReadLine();
}
//@overrideing calculatePay method
public override void calculatePay()
{
Console.WriteLine("Weekly Salary:{0}", wage * hours);
Console.WriteLine("Annual Salary:{0}", wage * hours*52);
}
//@override abstract method dispaly employee information
public override void DisplayEmployeeInformation()
{
Console.WriteLine("*********************** Collecting Employee's Basic Data*********");
Console.WriteLine(" First Name:{0}", firstName);
Console.WriteLine(" Last Name:{0}", lastName);
Console.WriteLine(" Gender:{0}", gender);
Console.WriteLine(" No of Dependencies:{0}", noOfdependents);
Console.WriteLine(" Health Insurance:{0}", healthInsure);
Console.WriteLine(" LifeInsurace:{0}", lifeInsure);
Console.WriteLine(" Number of Vacancies:{0}", vacation);
Console.WriteLine(" Wages[0-75]:{0}", wage);
Console.WriteLine(" Hours[0-40]:{0}", hours);
Console.WriteLine(" Catogiry:{0}", cat);

}

}


//SalariedEmployee class emplementing abstract Employee class


class SalariedEmployee : Employee
{
string firstName;
string lastName;
char gender;
int noOfdependents;
int annSalary;
string healthInsure;
int lifeInsure;
int vacation;
//int mLevel;
//@override collectEmployeeinformation method
public override void CollectEmployeeInformation()
{
Console.Write(" Enter First Name");
firstName = Console.ReadLine();
Console.Write(" Enter Second Name");
lastName = Console.ReadLine();
Console.Write(" Enter gender");
gender = Char.Parse(Console.ReadLine());
Console.Write(" Enter number of Dependents");
noOfdependents = Int32.Parse(Console.ReadLine());
Console.Write(" Enter Health insurance");
healthInsure = Console.ReadLine();
Console.Write(" Enter Life insurance amount:");
lifeInsure = Int32.Parse(Console.ReadLine());
Console.Write(" Enter Number of vacations:$");
vacation = Int32.Parse(Console.ReadLine());
//Console.Write("Enter Annual Salary:$");
//annSalary = Int32.Parse(Console.ReadLine());
Console.Write(" Enter Annual Salaray:$");
annSalary = Int32.Parse(Console.ReadLine());
}


//@overrideing calculatePay method
public override void calculatePay()
{
Console.Write(" Weekly Salary:", annSalary/52);

}
//@override abstract method dispaly employee information
public override void DisplayEmployeeInformation()
{
Console.WriteLine("*********************** Collecting Employee's Basic Data*********");
Console.WriteLine(" First Name:{0}", firstName);
Console.WriteLine(" Last Name:{0}", lastName);
Console.WriteLine(" Gender:{0}", gender);
Console.WriteLine(" No of Dependencies:{0}", noOfdependents);
Console.WriteLine(" Health Insurance:{0}", healthInsure);
Console.WriteLine(" LifeInsurace:{0}", lifeInsure);
Console.WriteLine(" Number of Vacancies:{0}", vacation);
Console.WriteLine(" Annual Salary :{0}", annSalary);

}
}

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

//create objects to hourly employee and salaried employee
Employee hourEmp = new HourlyEmployee();
Employee SalEmp = new SalariedEmployee();
//calling methods of hourly employee
hourEmp.CollectEmployeeInformation();
hourEmp.DisplayEmployeeInformation();
hourEmp.calculatePay();

//calling methods of salaried employee
SalEmp.CollectEmployeeInformation();
SalEmp.DisplayEmployeeInformation();
SalEmp.calculatePay();
}
}