Question

C# iLab 6 of 7: Abstract Class and Polymorphism.. This week Ilab any one help… Thanks!!!!

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 anobject based on Employee. Only objects based on Salaried and Hourly will be allowed. The abstract CalculatePay() method in Employee will force the child classes toimplement CalculatePay().
We are going to implement Polymorphism and dynamic binding by creating generalized methods that accept generalized Employee objects to collect input, and displayinformation. 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 isalso italicized, which means that it is a pure virtual function and needs to be implemented in the derived classes.

STEP 2: Create the Project

You will want to use the Week 5 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 newproject and copy the files.

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

STEP 3: Modify the Employee Class

Make the Employee class abstract.
Define CalculatePay() as an abstract method.
STEP 4: Create Generalized Input Methods

Create a Utilities class to put the methods of Steps 4 and 5. Note that these methods must be declared as static in order to call them from within Main, withoutcreating a Utilities object. Create a method called CollectEmployeeInformation that accepts as an argument an Employee object and prompts the user for all theemployee attributes, retrieves the attributes, makes any necessary conversions, and then sets the attribute values in the object. [Hint: In order to be able tocollect all information for the derived classes as well, you will need to create a base class method called ReadEmployeeData in the Employee class, which you willthen override in the derived classes to capture the required info per class. Call the ReadEmployeeData method within the CollectEmployeeInformation method.]

Show an example of a try-catch block in your code, as shown in the code snippet below: The "try" portion of the code looks for an error. If an error occurs parsingthe integer, it jumps down to the "catch" portion of the code and displays the error message. Because badInput is still true, it loops back to the "do" and startsover. Once the integer is parsed correctly, badInput is set to false so it exits the loop and correctly sets the value for vacation.

bool badInput = true;
string strVacation = ""; //Must be initialized
int vacation = 0; //Must be initialized
do {
try {
Console.Write("Please enter vacation days: ");
strVacation = Console.ReadLine();
vacation = Int32.Parse(strVacation);//Possible Error
badInput = false;
}
catch
{
Console.WriteLine("Please enter a valid value!");
}
} while(badInput);STEP 5: Create a Generalized Output Method

Create a method called DisplayEmployeeInformation that accepts an Employee object, provides an output header string, and then displays the Employeeinformation.

STEP 6: Modify the Main Method

Create an array of employee objects with:
Employee employeeList[] = new Employee[2];

For the first employee, create a salaried employee.
For the second employee, create an hourly employee.
Call the CollectEmployeeInformation method passing in the derived object, and after each object is created, call the DisplayNumberEmployees method.
Call the DisplayEmployeeInformation method for each object in the array list.

STEP 7: 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, modify your code as necessary, and rebuild.

Your output should resemble the following:

On-screen output display:
Welcome the Abstract employee Inheritance Hierarchy Program
CIS247, Week 6 Lab
Name: Solution

This program tests an Abstract emloyee Inheritance Hierarchy

*********************** Collecting Employee's Basic Data**********************

Enter employee's first name: Kate
Enter employee's last name: Perry
Enter employee's gender: F
Enter employee's number of dependents: 2
Enter employee's health insurance type: Full
Enter employee's life insurance amount: 1500
Enter employee's number of vacation: 10
Enter employee's annual salary: $25200
Enter employee's management level: 2

*********************** Collecting Employee's Basic Data**********************

Enter employee's first name: Jon
Enter employee's last name: Ross
Enter employee's gender: M
Enter employee's number of dependents: 1
Enter employee's health insurance type: Partial
Enter employee's life insurance amount: 700
Enter employee's number of vacation: 20
Enter employee's wage [10, 751: 35
Enter employee's hours worked <0, 50>: 40
Enter hourly employee's category: Part Time

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

First Name
: Kate

Last Name
: Perry

Gender
: Female

Dependents
: 2

Annual Salary
: $25,200.00

Weekly Pay
: $581.54

Health Insurance
: Full

Life Insurance
: $1,500.00

Vacation
: 10

Employee Type
: SALARIED

Management Lv1.
: 2

Annual Salary
: $25,200.00

Weekly Pay
: $581.54

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

First Name
: Jon

Last Name
: Ross

Gender
: Male

Dependents
: 1

Annual Salary
: $72,800.00

Weekly Pay
: $1,400.00

Health Insurance
: Partial

Life Insurance
: $700.00

Vacation
: 20

Employee Type : HOURLY

Category
: part time

Wage
: $35.00

Hours
: 40

Annual Salary
: $72,800.00

Weekly Pay
: $1,400.00

Total Number of Employess in Database: 2

Thank you for using the Abstract Employee Inheritance Hierarchy

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

Solutions

Expert Solution
No answers


Submit Your Answer