Scenario and Summary The objective of the lab is to take the UML Class diagram a
ID: 3644575 • Letter: S
Question
Scenario and Summary
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.
Override the base class calculatePay() method.
Override the displayEmployee() method.
STEP 1: Understand the UML Diagram
Notice the change in UML diagram. It is common practice to leave out the 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 an accessor (getter) and a mutator (setter) for every class attribute.
Employee #firstName : string #lastName : string #gender : char #dependents : int #annualSalary : double #benefit : Benefit -static numEmployees : int = 0 +Employee() +Employee(in fname : string, in lname : string, in gen : char, in dep : int, in benefits : Benefit) +static getNumEmployees() : int +CalculatePay() : double +displayEmployee() : void Benefit -healthinsurance : string -lifeinsurance : double -vacation : int +Benefit() +Benefit(in hins : string, in lins : double, in vac : int) +displayBenefits() : void Salaried -MIN_MANAGEMENT_LEVEL : int = 0 -MAX_MANAGEMENT_LEVEL : int = 3 -BONUS_PERCENT : double = 10 -managementLevel : int +Salaried() +Salaried(in fname : string, in lname : string, in gen : char, in dep : int, in sal : double, in ben : Benefit, in manLevel : int) +Salaried(in sal : double, in manLevel : int) +CalculatePay() : double +displayEmployee() : void Hourly -MIN_WAGE : double = 10 -MAX_WAGE : double = 75 -MIN_HOURS : double = 0 -MAX_HOURS: double = 50 -wage : double -hours : double -category : string +Hourly() +Hourly(in wage : double, in hours : double, in category : string) +Hourly(in fname : string, in lname : string, in gen : char, in dep : int, in wage : double, in hours : double, in ben : Benefit, in category : string) +CalculatePay() : double +displayEmployee() : void
STEP 2: Create the Project
Before you move on to the next step, build and execute the Week 5 project.
STEP 3: Modify the Employee Class
Using the updated Employee class diagram, modify the attributes to be protected.
STEP 4: Create the Salaried Class
Using the UML Diagrams from Step 1, create the Salaried classes, 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 base class constructor and pass the correct arguments to the base 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 for each of the management levels (i.e., bonus percentage = managementLevel * .10). The bonus percentage should be implemented as a constant.
Override the displayEmployee() method to add the management level to the employee information.
STEP 5: Label Title
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 base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.
The valid category types are "temporary", "part time", and "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 Employee setAnnualSalary method and set the annual salary by multiplying the weekly pay by 50.
Override the displayEmployee() method to add the category to the hourly employee information.
STEP 6: Label Title
Using previous weeks' assignments as an example, create at least one Employee, Hourly, and Salaried employee.
For each object created, display the number of employees created.
For each object created, write statements to exercise each of the public methods listed in the Class diagram.
For each object created, invoke the object's displayEmployee() method to display the employee's information.
For employee, the following information needs to be displayed:
Partial Sample output
Screenshot of program output that reads: Employee Information ________________________________________ Name: Nana Liu Gender: F Annual Salary: 60000.00 Weekly Salary: 1153.85 Benefit Information ________________________________________ Health Insurance: PPO Life Insurance: 1.50 Vacation: 20 days --- Number of Employee Object Created --- Number of employees: 1
For salaried employee, the following information needs to be displayed:
Partial Sample output
Screenshot of program output that reads: Name: Jackie Chan Gender: M Dependents: 1 Annual Salary: 50000.00 Weekly Salary: 1250.00 Benefit Information ________________________________________ Health Insurance: HMO Life Insurance: 100.00 Vacation: 16 days Salaried Employee Management Level: 3 --- Number of Employee Object Created --- Number of employees: 2
For hourly employee, the following information needs to be displayed:
Partial Sample output
Screenshot of program output that reads: Name: James Bond Gender: M Dependents: 0 Annual Salary: 100000.00 Weekly Salary: 2000.00 Benefit Information ________________________________________ Health Insurance: PPO Life Insurance: 5.00 Vacation: 17 days Hourly Employee Category: Unknown Wage: 40.00 Hours: 50.00 --- Number of Employee Object Created --- Number of employees: 3
STEP 7: Compile and Test
When done, compile and run your code.
Then, debug any errors until your code is error-free.
Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.
Below is the complete sample program output for your reference.
Screenshot of program output that reads: ************** Employee 1 ************** Please enter your First Name Nana Please enter your Last Name Liu Please enter your Gender Female Please enter your Dependents 2 Please enter your Annual Salary 60000 Please enter your HealthInsurancePPO Please enter your LifeInsurance1.5 Please enter your Vacation Days20 Employee Information ________________________________________ Name: Nana Liu Gender: F Annual Salary: 60000.00 Weekly Salary: 1153.85 Benefit Information ________________________________________ Health Insurance: PPO Life Insurance: 1.50 Vacation: 20 days --- Number of Employee Object Created --- Number of employees: 1 ************** Employee 2 ************** Please enter your First Name Jackie Please enter your Last Name Chan Please enter your Gender Male Please enter your Dependents 1 Please enter your HealthInsuranceHMO Please enter your LifeInsurance100 Please enter your Vacation Days16 Employee Information ________________________________________ Name: Jackie Chan Gender: M Dependents: 1 Annual Salary: 50000.00 Weekly Salary: 1250.00 Benefit Information ________________________________________ Health Insurance: HMO Life Insurance: 100.00 Vacation: 16 days Salaried Employee Management Level: 3 --- Number of Employee Object Created --- Number of employees: 2 *************** Employee 3 *************** Please enter your First Name James Please enter your Last Name Bond Please enter your Gender Male Please enter your Dependents 0 Please enter your Health InsurancePPO Please enter your Life InsurancePPO Please enter your Vacation Days17 Employee Information _______________________________________ Name: James Bond Gender: M Dependents: 0 Annual Salary: 100000.00 Weekly Salary: 2000.00 Benefit Information ________________________________________ Health Insurance: PPO Life Insurance: 5.00 Vacation: 17 days Hourly Employee Category: Unknown Wage: 40.00 Hours: 50.00 --- Number of Employee Object Created --- Number of employees: 3 The end of the CIS247C Week 5 iLab. Press any key to continue...
Explanation / Answer
// Employee.cs class Employee { //Private data members private string firstName; private string lastName; private char gender; private int dependents; private double annualSalary; //number of employees private static int numEmployees = 0; //Default Constructor public Employee() { firstName = "not given"; lastName = "not given"; gender = 'U'; dependents = 0; annualSalary = 20000; //updates number of employees numEmployees++; }//End of Default Constructor //Argumented Constructor public Employee(string first, string last, char gen, int dep, double salary) { firstName = first; lastName = last; gender = gen; dependents = dep; annualSalary = salary; //updates number of employees numEmployees++; }//End of Default Constructor //Calculates weekly pay public double CalculatePay() { return annualSalary / 52; }//End of CalculatePay method //Displays all the data of the employee public void DisplayEmployee() { 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()); }//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; } } //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 foe annual salary public void SetAnnualSalary(double salary) { annualSalary = salary; } //End of SetAnnualSalary method //returns number of employees created public static int GetNumberOfEmployees() { return numEmployees; } //overloaded method of setDependents with string parameter public void SetDependents(string dep) { dependents = Convert.ToInt32(dep); } //overloaded method of setAnnualSalary with string parameter public void SetAnnualSalary(string salary) { annualSalary = Convert.ToDouble(salary); } } // Program.cs class Program { static void Main(string[] args) { //Instantiating employee object using default constructor Employee emp = new Employee(); //Gets the employee information from the console 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(); //Sets the read information to the emp object emp.FirstName = first; emp.LastName = last; emp.Gender = gen; //setting dependets using overloaded method SetDependents //that accepts string type argument emp.SetDependents(dep); //setting salary using overloaded method SetAnnualSalary //that accepts string type argument emp.SetAnnualSalary(salary); //Displaying object data to the console. Console.WriteLine(" ***************** Employee Information *****************"); emp.DisplayEmployee(); Console.WriteLine("Total employees : {0} ", Employee.GetNumberOfEmployees()); //Creates another employee object using argumented construtor Employee emp2 = new Employee("Mari", "Noia", 'F', 5, 24000.0); //Displaying object data to the console. Console.WriteLine(" ***************** Employee Information *****************"); emp2.DisplayEmployee(); Console.WriteLine("Total employees : {0} ", Employee.GetNumberOfEmployees()); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.