CIS247A Week 5 iLab Composition Inheritance and Polymorphism

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:

  1. Create a derived class called Salaried that is derived from Employee.
  2. Create a derived class called Hourly that is derived from Employee.
  3. Create generalized input methods that accept any type of Employee or derived Employee object
  4. Create generalized output methods that accept any type of Employee or derived Employee object
  5. Override the base class CalculatePay method
  6. Override one of the base class CalculateWeeklyPay methods

Deliverables
Due this week:
Before you post your lab in the dropbox, copy your entire program into a Notepad file and post that. I do not need you to zip the project or give me screen shots of the output.

iLAB STEPS
STEP 1: Understand the UML Diagram
Analyze and understand the object UML diagram, which models the structure of the program:

  1. There are two new Employee derived classes (1) Salaried and (2) Hourly that are derived from the Employee class.
  2. The Employee class contains a new attribute employeeType and a new constructor that accepts as an argument the assigned employee type.
  3. Both the Salaried and the Hourly classes override only the CalculateWeeklyPay method of the Employee class (note, this is the method without any parameters.)
  4. The Salaried class has one attribute “managementLevel” that has possible values from MIN_MANAGEMENT_LEVEL to MAX_MANAGEMENT_LEVEL and a BONUS_PERCENT.
  5. The Salaried class has a default constructor and parameterized constructor that accepts all the general employee information plus the management level.
  6. The Hourly has a wage attribute, which respresents the hourly wage that ranges from MIN_WAGE to MAX_WAGE, a hours attributes, which represents the number of hours worked in a week that ranges from MIN_HOURS to MAX_Hours, and a category attributes that accepts string values.
  7. The Hourly class has a default constructor and parameterized constructor that accepts all the general employee information plus the hours and wage value.
  8. The Presentation Tier contains two new classes (1) The EmployeeInput class and the EmployeeOutput class
  9. The EmployeeInput class contains three static methods:
    • CollectEmployeeInformation, which accepts any type of Employee object as a argument.
    • CollectHourlyInformation, which accepts only Hourly objects as an argument.
    • CollectSalariedInformation, which accepts only Salaried objects as an argument.
  10. The EmployeeOutput class contains two methods
    • DisplayEmployeeInformation, which accepts any Employee type as an argument.
    • DisplayNumberObjects method.
  11. All the access specifers for the Employee attributes are changed to protected and are depicted with the “#” symbol.

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 previous weeks labs to create the project and the folders.

  1. Create a new project named “CIS247_WK5_Lab_LASTNAME”. An empty project will then be created.
  2. Delete the default Program.cs file that is created.
  3. Add the Logic Tier, Presentation Tier, and Utilities folders to your proejct
  4. Add the Week 4 project files to the appropraties folders.
  5. Update the program information in the ApplicationUtilities.DisplayApplicationInformation method to reflect your name, current lab, and program description

Note: as an alternative you can open up the Week 4 project and make modifications to the existing project. Remember, there is a copy of your project in the zip file you submitted for grading.
Before attempting this week’s steps ensure that the Week 4 project is error free.

STEP 3: Modify the Employee Class

  1. Change the access specifier for all the private attributes to protected.
  2. Add the new attribute employeeType, along with a “read only” property (that is only a “get” method) to access the employee type value.
  3. Add a new constructor that only accepts the type attribute, which is then used to set the employeeType value. Also, this constructor should initialize all the default values. You can call the default constructor using the syntax:
     public Employee(string employeeType) : this() { }
    
  4. Modify the parameterized constructor that accepts the employee information to accept the employee type, and then set the employeeType with this value.
  5. Modify the ToString Method to include the employee type.

STEP 4: Create the Salaried Class

  1. Using the UML Diagrams, create the Salaried class, ensuring to specify that the Salary class inherits from the Employee class.
  2. 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.
  3. Override the CalculateWeeklyPay 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). 
    
  4. Override the ToString method to add the management level to the employee information.

STEP 5: Create the Hourly Class

  1. Using the UML Diagrams, create the Hourly classes, ensuring to specify that the Hourly class inherits from the Employee class.
  2. 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. Notice, that the Hourly employee DOES NOT have an annual salary, which we will then have to calculate (see below).
  3. Create a Category property (get/set) and the valid category types are “temporary”, “part time”, “full time”.
  4. Create a Hours property (get/set) for the hours attributes and validate the input using the constants shown in the UML diagram, but since an Hourly employee does not have a formal annual salary we will need to calculate this each time the hour (and wage) properties are set. Add the following code after the validation code in the hours property:
    base.AnnualSalary = CalculateWeeklyPay() * 48; (assumes working 48 weeks a year).
    
  5. Create an Wage property (get/set) for the wage attributes and validate the input using the constants shown in the UML diagram. Add the following code after the validation code in the wage property:
    base.AnnualSalary = CalculateWeeklyPay() * 48; (assumes working 48 weeks a year)
    
  6. Override the CalculateWeeklyPay method by multiplying the wages by the number of hours. 7. Update the ToString method to add the category, hours, and wages to the hourly employee information.

STEP 6: Create the EmployeeInput Class

  1. Create a new class in the Presentation Tier folder called “EmployeeInput”
  2. Create a static void method called CollectEmployeeInformation that has a single Employee parameter. The declaration should look something like the following:
    public static void CollectEmployeeInformation(Employee theEmployee)
    
  3. Write code statements similiar to what you created in the Week 4 project to collect the generic employee information from the user, except instead of using specific employee objects use the “theEmployee” parameters. For example:
    In Week 4, you had something like:

    employee1.FirstName = InputUtilities.GetStringInputValue(“First name”);
    

    In the CollectionEmployeeInformation method this can be translated to the following;

    theEmployee.FirstName = InputUtilities.GetStringInputValue(“First name”);
    
  4. Write statements to collect all the generic employee information, including the Benefits information, as you did in the Week 4 project. However, since not all derived types have a AnnualSalary value, DO NOT collect the annual salary data.
  5. Create a new static void method called CollectEmployeeInformation that accepts an Hourly employee object. Using the InputUtilities methods write statements to collect the wage and hours from the user.
  6. Create a new static void method called CollectSalariedInformation that accepts a Salaried employee object. Using the InputUtilties methods write statements to collect the management level and the annual salary.

STEP 7: Create the Main Program

  1. Create an array of type Employee that will hold three employee objects. Create three new objects, one Employee, one Hourly and one Salaried in positions 0, 1 and 2 of the array respectively. Make sure to use the constructors the accept the employee type and provide appropriate values for the employee type (e.g. “Generic”, “Hourly”, “Salaried”).
  2. Using a FOR loop iterate through the array and collect all the generic employee information, using the EmployeeInput.CollectEmployeeInformation method.
  3. If the current item in the array is an Hourly object, then use the EmployeeInput.CollectHourlyInformation method to collect the hourly information.
  4. If the current item in the array is a Salaried object, then use the EmployeeInput.CollectSalariedInformation method to collect the salaried information. Use the following if statement to determine the specific type of object:
    if (employeeList[i] is Hourly) 
        EmployeeInput.CollectHourlyInformation((Hourly)employeeList[i]);
    else if (employeeList[i] is Salaried)          
        EmployeeInput.CollectSalariedInformation((Salaried)employeeList[i]);
    
  5. After the information has been collected display the employee information using the EmployeeOutput.DisplayEmployeeInformation method.
  6. Before terminating the program display the number of employee objects that have been created.

STEP 8: Compile and Test

  1. When done, compile and run your program.
  2. Then debug any errors until your code is error-free.
  3. Check your output to ensure that you have the desired output and modify your code as necessary and rebuild.




The solution includes a Visual Studio (c#) project

  • Attachments [Move over files to preview content of those files]
    • CIS247A_iLab_5.zip (148.23 KB)
      • CIS247A-Week-5-Screenshot.png
      • Visual Studio project
        • CIS247A_WK5_Lab
          • CIS247A_WK5_Lab
          • CIS247A_WK5_Lab.sln
          • CIS247A_WK5_Lab.v12.suo
    Preview Benefit.cs
    xxxxxxx xxxxx xxxxxx xxx_xxxx_xxxxxxxxx = 1000;
    xxxxxxx xxxxx xxxxxx xxx_xxxx_xxxxxxxxx = 10000000;
    xxxxxxx xxxxx xxx xxx_xxxxxxxx = 0;
    xxxxxxx xxxxx xxx xxx_xxxxxxxx = 100;
    xxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxx;
    private double lifeInsuranceAmount; private int vacation; public Benefit() { vacation = MAX_VACATION; lifeInsuranceAmount = MAX_LIFE_INSURANCE; healthInsuranceCompany = DEFAULT_HEALTH_INSURANCE; } public Benefit(String health,double life,int vacat) { HealthInsuranceCompany = health; LifeInsuranceAmount = life;
    xxxxxxxx = xxxxx;
    }
    xxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxx
    {
    xxx
    {
    Preview Employee.cs
    xxxxxxxxx xxxxxx xxxxxxxx; //xxxx xxxx xx xxx xxxxxxxx
    xxxxxxxxx xxxx xxxxxx; //xxxxxx xx xxx xxxxxxxx
    xxxxxxxxx xxx xxxxxxxxxx; //xxxxxxxxx xx xxx xxxxxxxx
    xxxxxxxxx xxxxxx xxxxxxxxxxxx; //xxxxxx xxxxxx xx xxx xxxxxxxx
    protected const int MIN_DEPENDENTS = 0; //Default value for min dependants protected const int MAX_DEPENDENTS = 10; //Default value for max dependants protected const double MIN_SALARY = 20000; //Default value for min salary protected const double MAX_SALARY = 100000; //Default value for max salary protected const string DEFAULT_NAME = "not given"; //Default value for name protected const char DEFAULT_GENDER = 'U'; //Default value for gender protected static int numEmployees = 0; //Counter variablefor employee objects created so far //Benefit object public Benefit benefit;
    xxxxxxxxx xxxxxx xxxxxxxxxxxx;
    xxxxxx xxxxxx xxx xxxxxxxxxxxxxxx //xxxxxxxx xx xxx xxxxx xx xxxxxx xxxxxxxx xxxxxxxxxxxx
    {
    xxx //xxxxxx xxx xxxxxxxxxxxx
    {
    Preview Hourly.cs
    xxxxxxx xxxxx xxx xxx_xxxx = 75;
    xxxxxxx xxxxx xxx xxx_xxxxx = 0;
    xxxxxxx xxxxx xxx xxx_xxxxx = 50;
    xxxxxxx xxxxx xxxxxx xxxxx_xxxxxxx = 10;
    xxxxxxx xxxxxx xxxx;
    private double hours; private string category; public Hourly():base() { wage = 10; hours = 1; } public Hourly(String type):base(type) { wage = 10; hours = 1; }
    xxxxxx xxxxxx(xxxxxx xxxxx, xxxxxx xxxx, xxxx xxx, xxx xxx, xxxxxx xxxxxx, xxxxxxx xxxxxxx, xxxxxx xxxxxxxxxxxx, xxxxxx xxxx,xxxxxx xxxxx,xxxxxx xxxxxxxx)
    : xxxx(xxxxx, xxxx, xxx, xxx, xxxxxx, xxxxxxx, xxxxxxxxxxxx)
    {
    xxxx = xxxx;
    xxxxx = xxxxx;
    xxxxxxxx = xxxxxxxx;
    Preview Salaried.cs
    xxxxxxx xxxxx xxx xxx_xxxxxxxxxx_xxxxx = 3;
    xxxxxxx xxxxx xxxxxx xxxxx_xxxxxxx = 10;
    xxxxxxx xxx xxxxxxxxxxxxxxx;
    xxxxxx xxxxxxxx():xxxx()
    {
    managementLevel = 1; } public Salaried(String type) : base(type) { managementLevel = 1; } public Salaried(string first, string last, char gen, int dep, double salary, Benefit benefit, String employeeType,int manageLevel):base(first, last, gen, dep, salary, benefit, employeeType) { ManagementLevel = manageLevel; } public int ManagementLevel
    {
    xxx
    {
    xxxxxx xxxxxxxxxxxxxxx;
    }
    xxx
    Preview EmployeeInput.cs
    xxxxx xxxxxx;
    xxxxx xxxxxx.xxxxxxxxxxx.xxxxxxx;
    xxxxx xxxxxx.xxxx;
    xxxxx xxxxxx.xxxx;
    namespace CIS247A_WK5_Lab { public class EmployeeInput { public static void CollectEmployeeInformation(Employee theEmployee) {
    xxxxxxxxxxx.xxxxxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxx("xxxxx xxxx"); //xxx xxxxx xxxx xxxxx xxxx xxx xxxx
    xxxxxxxxxxx.xxxxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxx("xxxx xxxx");//xxx xxxx xxxx xxxxx xxxx xxx xxxx
    xxxxxxxxxxx.xxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxx("xxxxxx");//xxx xxxxxx xxxxx xxxx xxx xxxx
    xxxxxxxxxxx.xxxxxxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxx("# xxxxxxxxxx");//xxx xxxxxxxxx xxxxx xxxx xxx xxxx
    xxxxxxxxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxx("xxxxxx xxxxxxxxx xxxxxxx");
    xxxxxxxxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxx("xxxx xxxxxxxxx xxxxxx");
    Preview EmployeeOutput.cs
    xxxxx xxxxxx;
    xxxxx xxxxxx.xxxxxxxxxxx.xxxxxxx;
    xxxxx xxxxxx.xxxx;
    xxxxx xxxxxx.xxxx;
    namespace CIS247A_WK5_Lab { public class EmployeeOutput { public static void DisplayEmployeeInformation(string employeeType) { ApplicationUtilities.DisplayDivider(employeeType + " Employee");
    }
    xxxxxx xxxxxx xxxx xxxxxxxxxxxxxxxxxxxx()
    {
    xxxxxxx.xxxxxxxxx("xxxxx xxxxxx xx xxxxxxxxx xx xxxxxxxx: " + xxxxxxxx.xxxxxxxxxxxxxxx);
    }
    }
    Preview Program.cs
    xxxxxx xxxx xxxx(xxxxxx[] xxxx)
    {
    xxxxxxxx[] xxxxxxxxxxxx = xxx xxxxxxxx[3];
    xxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx(); //xxxxxxx xxx xxxxxx xxx xxx xxxxxxxxxxx
    ApplicationUtilities.DisplayDivider("Start Program"); //Show heading that the program has started employeeList[0] = new Employee("Generic"); employeeList[1] = new Hourly("Hourly"); employeeList[2] = new Salaried("Salaried"); Console.WriteLine(""); for (int i = 0; i < 3; i++) { EmployeeInput.CollectEmployeeInformation(employeeList[i]); Console.WriteLine("");
    xx (xxxxxxxxxxxx[x] xx xxxxxx)
    xxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx((xxxxxx)xxxxxxxxxxxx[x]);
    xxxx xx (xxxxxxxxxxxx[x] xx xxxxxxxx)
    xxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxx((xxxxxxxx)xxxxxxxxxxxx[x]);
    xxxxxxx.xxxxx(xxxxxxxxxxxx[x].xxxxxxxx()); //xxxxxxx xxxxx xxxxxxxx xxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxx();// xxxxxx x xxxxx xx xxxx xxxx xxxxx xx xxxxx x xxx xx xxxxxxxx
    Preview ApplicationUtilities.cs
    xxxxx xxxxxx;
    xxxxx xxxxxx.xxxxxxxxxxx.xxxxxxx;
    xxxxx xxxxxx.xxxx;
    xxxxx xxxxxx.xxxx;
    namespace CIS247A_WK5_Lab { public class ApplicationUtilities { public static void DisplayApplicationInformation() { Console.WriteLine("Welcome the Basic Employee Program");
    xxxxxxx.xxxxxxxxx("xxx247x, xxxx 5 xxx");
    xxxxxxx.xxxxxxxxx("xxxx: xxxx xxx");
    xxxxxxx.xxxxxxxxx("xxxx xxxxxxx xxxxxxx xxxx xxxxx xx x xxxxxx, xxxx xxxxx xxx \xxxxxxxxxxxx xxxx xxxxxxxxxx xxx xxxxxxx xxx xxxxx xx xxxxxxxx xxxxxxx xxxxx xxxxxxxxx xxx xxxxxxxx.");
    xxxxxxx.xxxxxxxxx();
    }
    xxxxxx xxxxxx xxxx xxxxxxxxxxxxxx(xxxxxx xxxxxxxxxxx)
    Preview InputUtilities.cs
    {
    xxxxxx xxxxxxxx = xxxxxx.xxxxx;
    xxxxxxx.xxxxx("xxxxx xxx " + xxxxxxxxx + ": ");
    xxxxxxxx = xxxxxxx.xxxxxxxx();
    return strInput; } public static string getStringInputValue(string inputType) { string value = String.Empty; bool valid = false; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!String.IsNullOrEmpty(inputString)) {
    xxxxx = xxxxxxxxxxx;
    xxxxx = xxxx;
    }
    xxxx
    {
    xxxxx = "xxxxxxx xxxxx";


Price: $15 $20 Save $5 (25%)

Buy Now

Add to Cart

Note: We offer a discount for buyers who purchase multiple items.