CIS 247A Week 3 iLab Overloaded Methods and Static Methods Variables

$20

Description

CIS 247A Week 3 iLab Overloaded Methods and Static Methods Variables

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 static variable called numEmployees that holds an int and initialize it to zero. This will allow us to count all the Employee objects created in the main class.
  2. Increment numEmployees in all of the constructors.
  3. Add an overloaded method of CalculatePay that will accept a new, or modifed, annual salary
    value. We will then have two versions of the CalculatePay method (1) that uses the current value of the annual salary for the calculation and (2) one that updates the annual salary with a new value before the calculation.
  4. Using properties add accessor (get) and mutator (set) methods to access each of the private attributes and to validate the attribute values before they are set.

iLAB STEPS
STEP 1: Understand the UML Diagram

  1. Analyze and understand the object UML diagram, which models the structure of the program.
  2. There are no design changes to the Presentation Tier from the previous project and InputUtilities and ApplicationsUtilities classes are used without modification (except for changing the Application Information).
  3. The default values for each of the attributres have been declared as a constants, which is indicated by the ALL_CAPS in the name, and the attributes are then set using the default values
  4. Each of the attributes have been specified as private.
  5. The accessors (get) and mutators (set) are not shown on the class diagram, but it is ASSUMED that each private attribute has a corresponding property that contains the get and set methods.
  6. The “static” modifier for the numEmployees attribute means that there is only one copy of the variable that is then shared by all the objects of the class.
  7. There is a second CalculatePay method that overloads the existing CalculatePay method
  8. While not shown on the class diagram, the property for numEmployees will only have a get method, which means it will be a “read only” method. (A property with only and set method is a “wrute-only” property).

STEP 2: Create the Project
You will want to use the Week 2 project as the starting point for the lab. To do this, you will want to create a new project by following these steps:

    1. Create a new project named “CIS247_WK3_Lab_LASTNAME”. An empty project will then be created.
    2. Delete the default Program.cs file that is created.
    3. Click on Project->Add Existing Item…. Select the .cs files containing the InputUtilities,
      ApplicationUtilities, Employee, and Program classes from your project folder from last week‟s lab.
    4. The namespaces for the classes should all be “Employee”, but you should verify that the namespaces for all the classes are the same.
    5. Update the program information in the ApplicationUtilities.DisplayApplicationInformation method to reflect your name, current lab, and program description.
    6. Build and execute the project.

For each week‟s assignments you will follow these steps create a new project that reuses the program from the previous week.

STEP 3: Modify the Employee
Be sure you follow proper commenting and programming styles (header, indentation, line spacing, etc.) that are specified in the Programming Conventions and Standards guide. Using the Employee class diagram as a guide modify the Employee class:

  1. Add the constants to the class using the following as an example:
    public const double MIN_SALARY = 20000;
  2. In the default constructor, update assignment statements to use the defined constants
  3. Change all the employee class attributes to private.
  4. Create a private static numEmployees variable and initialize it to zero
  5. Increment numEmployees by 1 in each of the constructors
  6. For each private attribute, create a well-named property that contains the get and set
    methods. The get method of the property only needs to return the value of the attribute; but the set method of each property needs to validate the provided value using the following validation rules:
    a. If the provided first or last values are empty, or a null value, then set the name to DEFAULT_NAME.
    b. If the provided gender value is „F‟, „f‟, „M‟, or „m‟ set the value; otherwise set the value to DEFAULT_GENDER.
    c. If the provided dependent value is between the MIN_DEPENDENTS and MAX_DEPENDENTS (inclusive) then set dependent to the provided value; if the provided value is less than MIN_DEPENDENTS set the dependents to MIN_DEPENDENTS; else if provided value is greater than MAX_DEPENDENTS set the dependents to MAX_DEPENDENTS.
    d. If the provided salary value is between the MIN_SALARY and MAX_SALARY (inclusive) the set the annualSalary to the provided value; if the provided value is less than MIN_SALARY set the annualSalary to MIN_SALARY; else if provided value is greater than MAX_SALARY set the annualSalary to MAX_SALARY.
    e. For the numEmployee attribute create a property called NumberEmployees that only contains a “get” method, external objects should NOT be allowed modify the numEmployee value. Since numEmployees is a static method, the property must be declared as static.
  7. In the parameterized constructor, change statements that set the attributes so that the properties are used, which ensures that attributes are validated prior to be set.
  8. Create the overloaded CalculateWeeklyPay method that accepts a double “modifiedSalary” argument. The method shall update the annualSalary attribute (use the AnnualSalary property to ensure the value is valid), and then return the updated weekly pay based on the new annual salary value.

STEP 4: Modify the Main Method
In the Main class, create code statements that perform the following operations. Be sure you follow proper commenting and programming styles (header, indentation, line spacing, etc.) and use the ApplicationUtiltities methods to logically separate the operations in the output.

To access a property of an object/class, you continue to use the DOT notation; however, a property DOES NOT require the parenthesis and you just use the assignment operator (=) to set or get the value, which makes using propertys very easy. For example to set the first name, the statement would look something like:

1
employee1.FirstName = “John”

To get the full name, the statement would look look something like:

1
theName = employee1.FirstName + ” ” + employee1.LastName

Notice, there is no use of parenethese, only the assignment operator, when using properties.
The Main method code from the previous week‟s lab performed the following operations, ensure that your project correctly implements these operations before moving on the new operations for this week.

  1. Display the program information.
  2. Create an Employee object using the default constructor.
  3. Prompt for and then set the first name, last name, gender, dependents, and annual salary.
    Remember to use the appropriate methods in the InputUtilties class to prompt for and retreive the values.
  4. Display the employee information.
  5. Create a second Employee object using the multi-argument constructor using data of your
    choosing that is the correct type and within the valid ranges for each of the attributes.
  6. Display the Employee information for the second employee object.
  7. Terminate the application

Once your code is working and implements the previous week‟s operations, modify the code to implement the following new requirements (updated code should implement all previous requirements except as noted below).

  1. After the first employee information is provided, display the number of employees created.
  2. Prompt the user to provide an updated annual salary for employee1, retrieve the value and
    invoke the overloaded CalculateWeeklyPay, and then display only the updated weekly pay.
  3. Create a third Employee object using the parameterized constructor setting each of the attributes with the following values: “Sue”, “Smith”, „F‟, 15, 500000.0
  4. Display the employee information for the third Employee object and verify that the dependents and annual salary values have been set to the maximum values by the properties. If not, make sure you change the parameterized constructor to use the properties to set the attributes.
  5. Display the number of employees created.

STEP 5: Compile and Test
When done, compile and execute your code. Debug 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. The following shows some sample output, but your output may look different.

STEP 6: Submit Deliverables
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.

Submit your lab to the Dropbox located on the silver tab at the top of this page. For instructions on how to use the Dropbox, read these Step-by-Step Instructions or watch this Dropbox Tutorial.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Add to cart