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

The objective of the lab is to take the UML Class diagram and enhance last week\

ID: 3651056 • Letter: T

Question

The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:

Create a class called Salaried that is derived from Employee.
Create a class called Hourly that is also derived from Employee.
Since all classes/objects inherit from the System.Object class, change the appropriate "DisplayClass" information method to override the System.Object.ToString() method.
Override the base class CalculatePay method
Deliverables

STEP 1: Understand the UML Diagram
Notice the change in UML diagram. It is common practice to leave out the properties or (accessors and mutators - getters and setters) from UML class diagrams, since there can be so many of them. Unless otherwise specified, it is assumed that there is a property or accessor (getter) and a mutator (setter) for every class attribute.


STEP 2: Create the Project
You will want to use the Week 4 project as the starting point for the lab. Before you move on to the next step, build and execute the Week 5 project.
Week4 Project
class Program
{
static void Main(string[] args)
{

Employee emp = new Employee();


Console.Write("Enter first name: ");
string first = Console.ReadLine();
Console.Write("Enter last name: ");
string last = Console.ReadLine();
Console.Write("Gender: ");
char gen = Console.ReadLine().First();
Console.Write("Dependents: ");
string dep = Console.ReadLine();
Console.Write("Annual Salary: $");
string salary = Console.ReadLine();
Console.Write("Enter health insurance (Full or Partial): ");
string health = Console.ReadLine();
Console.Write("Enter life insurance :$ ");
double life = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter vacation: ");
int vacation = Convert.ToInt32(Console.ReadLine());


emp.FirstName = first;
emp.LastName = last;
emp.Gender = gen;


emp.SetDependents(dep);


emp.SetAnnualSalary(salary);

emp.benefit.SetHealthInsurance(health);
emp.benefit.SetLifeInsurance(life);
emp.benefit.SetVacation(vacation);


emp.DisplayEmployee();

Console.WriteLine("Total employees : {0} ", Employee.GetNumberOfEmployees());

Benefit benefit1 = new Benefit("Full", 1000, 5);

Employee emp2 = new Employee("Mary", "Noia", 'F', 5, 24000.0, benefit1);

emp2.DisplayEmployee();
Console.WriteLine("Total employees : {0} ", Employee.GetNumberOfEmployees());
Console.Read();
}
}




}
class Employee : IEmployee
{

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

private static int numEmployees = 0;

public 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 double CalculatePay()
{
return annualSalary / 52;
}



public void DisplayEmployee()
{
Console.WriteLine("***************** Employee Information *****************");
Console.WriteLine("First Name: {0}", firstName);
Console.WriteLine("Last Name: {0}", lastName);
Console.WriteLine("Gender: {0}", gender);
Console.WriteLine("Dependents: {0}", dependents);
Console.WriteLine("Annual Salary: {0:c}", annualSalary);
Console.WriteLine("Weekly Pay: {0:c}", CalculatePay());
benefit.DisplayBenefits();
}


public string FirstName
{
set
{
firstName = value;
}
get
{
return firstName;
}
}



public string LastName
{
set
{
lastName = value;
}
get
{
return lastName;
}
}


public char Gender
{
set
{
gender = value;
}
get
{
return gender;
}
}


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

public double AnnualSalary
{
set
{
annualSalary = value;
}
get
{
return annualSalary;
}
}


public void SetDependents(int dep)
{
dependents = dep;
}


public void SetAnnualSalary(double salary)
{
annualSalary = salary;
}


public static int GetNumberOfEmployees()
{
return numEmployees;
}


public void SetDependents(string dep)
{
dependents = Convert.ToInt32(dep);
}


public void SetAnnualSalary(string salary)
{
annualSalary = Convert.ToDouble(salary);
}
}
}
interface IEmployee
{



double CalculatePay();

}





class Benefit
{



private string healthInsurance;

private double lifeInsurance;

private int vacation;



public Benefit()
{

}



public Benefit(string health, double life, int v)
{

healthInsurance = health;

lifeInsurance = life;

vacation = v;

}



public void DisplayBenefits()
{

Console.WriteLine("Health Insurance: {0}", healthInsurance);

Console.WriteLine("Life Insurance: {0}", lifeInsurance);

Console.WriteLine("Vacation: {0}", vacation);

}



public void SetHealthInsurance(string health)
{

healthInsurance = health;

}



public string GetHealthInsurance()
{

return healthInsurance;

}

public void SetLifeInsurance(double life)
{

lifeInsurance = life;

}

public double GetLifeInsurance()
{

return lifeInsurance;

}

public void SetVacation(int v)
{

vacation = v;

}

public int GetVacation()
{

return vacation;

}

}
}




STEP 3: Modify the Benefits Class
Change the DisplayBenefits method to override the System.Object.ToString method, ensuring that the method returns a string, and does not explicitly display the information, but just returns a string.
STEP 4: Modify the Employee Class

Using the updated Employee class diagram, modify the attributes so that they become protected.
Change the name of the DisplayEmployee method to "ToString", which then overrides the System.Object.ToString() method, and returns a string.
Delete the IEmployee interface, and remove the reference from the Employee class
STEP 5: Create the Salaried Class

Using the UML Diagrams from Step 1, create the Salaried class, ensuring to specify that the Salary class inherits from the Employee class.
For each of the constructors listed in the Salaried class ensure to invoke the appropriate super class constructor and pass the correct arguments to the super class constructor. This will initialize the protected attributes and update the numEmployees counter
The valid management levels are 0, 1, 2, and 3, and should be implemented as a constant.
Override the CalculatePay method to add a 10 percent bonus to the annualSalary depending on the management level. The bonus percent is a fixed 10 percent, and should be implemented as a constant. However, depending on the management level the actual bonus percentage fluctuates (i.e., actualBonusPercentage = managementLevel * BONUS_PERCENT).
Override the ToString method to add the management level to the employee information.
STEP 6: Create the Hourly Class

Using the UML Diagrams from Step 1, create the Hourly classes, ensuring to specify that the Hourly class inherits from the Employee class.
For each of the constructors listed in the Hourly class ensure to invoke the appropriate super class constructor and pass the correct arguments to the super class constructor. This will initialize the protected attributes and update the numEmployees counter.
The valid category types are "temporary", "part time", "full time";
The provided hours must be more than 0 hours and less than 50 hours, and the limits should be implemented as constants.
The provided wage must be between 10 and 75, and the limits should be implemented as constants.
Override the CalculatePay method by multiplying the wages by the number of hours.
Override the ToString method to add the category to the hourly employee information.
If you haven't done so already, make sure you identify the appropriate place(s) in the Hourly class to set the annualSalary attribute to a proper value (call the CalculatePay method to get the weekly pay and multiply the result by 52 in order to calculate and set the annualSalary).
STEP 7: Construct the Main Method


Create an array of type Employee and size 3. Create 3 new objects, one Employee, one Hourly and one Salaried in positions 0, 1 and 2 of the array respectively. Use any constructors you wish except the default.
Using a FOR loop, iterate through the array and call the ToString and CalculatePay methods of each object to display the weekly pay and the employee's information respectively.
Call the GetNumEmployees method to display the total number of employees instantiated.
STEP 8: Compile and Test

The output of your program should resemble the following:

On-screen output display:
Welcome the Employee Hierarchy Program
CIS247, Week 5 Lab
Name: Solution

This program tests an Employee inheritance hierarchy

*********************** Display Employee's Data **********************

Employee Type

GENERIC

First Name

Joe

Last Name

Doe

Gender

Male

Dependents

1

Annual Salary

$10,000.00

Weekly Pay

$192.31

Health Insurance

Partial

Life Insurance

$1,000.00

Vacation

2


*********************** Display Employee's Data ********************** Employee Type

SALARIED

First Name

Zoe

Last Name

Likoudis

Dependents

3

Management Lv1.

1

Annual Salary

$20,000.00

Weekly Pay

$423.08

Health Insurance

Full

Life Insurance

$2,000.00

Vacation

4



*********************** Display Employee's Data **********************

Employee Type

HOURLY

First Name

Kate

Last Name

Perry

Gender

Female

Dependents

0

Category

part time

Wage

$75.00

Hours

25

Weekly Pay

$1,875.00

Annual Salary

$97,500.00

Health Insurance

Partial

Life Insurance

$3,000.00

Vacation

8


total Number of Employess in Database: 3

Press the ESC key to close the image description and return to lecture



Image Description

Explanation / Answer

To view the answer go to http://goo.gl/wUFyk

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote