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

STEP 1: Understand the UML Diagram Notice the change in UML diagram. It is commo

ID: 3634166 • Letter: S

Question

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. Use the directions from the iLab Assignment of Week 3 (Step 2) on how to create a new project and copy the files.

Before you move on to the next step, build and execute the Week 5 project.

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


When done, compile and run your program.

Then debug any errors until your code is error-free.

Check your output to ensure that you have the desired output and modify your code as necessary and rebuild.

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

Dear, // Benefit.cs class Benefit { // data fields private string healthInsurance; private double lifeInsurance; private int vacation; //default constructor public Benefit() { } //argumented constructor public Benefit(string health, double life, int v) { healthInsurance = health; lifeInsurance = life; vacation = v; } //displays the data of the object public override string ToString() { return string.Format( "Health Insurance: {0} " + "Life Insurance : {1:c} " + "Vacation : {2}", healthInsurance, lifeInsurance, vacation); } //sets health insurance public void SetHealthInsurance(string health) { healthInsurance = health; } //returns health insurance public string GetHealthInsurance() { return healthInsurance; }//sets life insurance public void SetLifeInsurance(double life) { lifeInsurance = life; }//returns life insurance public double GetLifeInsurance() { return lifeInsurance; }//sets vacation public void SetVacation(int v) { vacation = v; }//returns vacation public int GetVacation() { return vacation; } } // Employee.cs class Employee { //Private data members protected string firstName; protected string lastName; protected char gender; protected int dependents; protected double annualSalary; //number of employees private static int numEmployees = 0; //benift object protected Benefit benefit; //Default Constructor public Employee() { firstName = "not given"; lastName = "not given"; gender = 'U'; dependents = 0; annualSalary = 20000; //updates number of employees numEmployees++; benefit = new Benefit("not given", 0, 0); }//End of Default Constructor //Argumented Constructor public Employee(string first, string last, char gen, int dep, double salary, Benefit benefit) { firstName = first; lastName = last; gender = gen; dependents = dep; annualSalary = salary; //updates number of employees numEmployees++; this.benefit = new Benefit(benefit.GetHealthInsurance(), benefit.GetLifeInsurance(), benefit.GetVacation()); }//End of Argumented Constructor //Calculates weekly pay public virtual double CalculatePay() { return annualSalary / 52; }//End of CalculatePay method //Displays all the data of the employee public override string ToString() { return string.Format( "Employee Type : {0} " + "First Name : {1} " + "Last Name : {2} " + "Gender : {3} " + "Dependents : {4} " + "Annual Salary : {5:c} " + "Weekly Pay : {6:c} {7}", "GENERIC", FirstName, LastName, (Gender == 'M') ? "Male" : "Female", Dependents, AnnualSalary, CalculatePay(), benefit.ToString()); }//End of DisplayEmployee method //Public properties //Property for first name of the employee public string FirstName { set { firstName = value; } get { return firstName; } }// End of FirstName method //Property for last name of the employee public string LastName { set { lastName = value; } get { return lastName; } }//End of LastName method //Gender of the employee public char Gender { set { gender = value; } get { return gender; } }//End of Gender method //The dependets public int Dependents { set { dependents = value; } get { return dependents; } }//End of the Dependents method //Annual salary public double AnnualSalary { set { annualSalary = value; } get { return annualSalary; } }//End of AnnualSalary method //Additional setter method for dependents public void SetDependents(int dep) { dependents = dep; }//End of SetDependents method //Additional setter method for annual salary public void SetAnnualSalary(double salary) { annualSalary = salary; } //End of SetAnnualSalary method //returns number of employees created public static int GetNumberOfEmployees() { return numEmployees; }//End of GetNumberOfEmployees method //overloaded method of setDependents with string parameter public void SetDependents(string dep) { dependents = Convert.ToInt32(dep); }//End of SetDependents method //overloaded method of setAnnualSalary with string parameter public void SetAnnualSalary(string salary) { annualSalary = Convert.ToDouble(salary); }//End of SetAnnualSalary method } // Salaried.cs class Salaried : Employee { // constant values for minmum and maximum management levels private const int MIN_MANAGEMENT_LEVEL = 0; private const int MAX_MANAGEMENT_LEVEL = 3; // bonus percentage private const double BONUS_PERCENT = 10.0; // employee management level private int managementLevel; // noargument constructor public Salaried() : base() { managementLevel = MIN_MANAGEMENT_LEVEL; } // 7-ArgumentException constructor public Salaried(string first, string last, char gen, int dep, double salary, Benefit benefit, int manLevel) : base(first, last, gen, dep, salary, benefit) { setManagementLevel(manLevel); } // 2-argument constructor public Salaried(double salary, int manLevel) : base() { AnnualSalary = salary; setManagementLevel(manLevel); } // helper method to set management level public void setManagementLevel(int manLevel) { if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel = MIN_WAGE && wage = MIN_HOURS && hours