Placeholder

CIS247A Week 3 iLab Overloaded Methods and Static Methods Variables

$9.99

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 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.
Increment numEmployees in all of the constructors.
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.
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.

Description

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 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.
Increment numEmployees in all of the constructors.
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.
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
Analyze and understand the object UML diagram, which models the structure of the program.
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).
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
Each of the attributes have been specified as private.
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.
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.
There is a second CalculatePay method that overloads the existing CalculatePay method
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:
Create a new project named “CIS247_WK3_Lab_LASTNAME”. An empty project will then be created.
Delete the default Program.cs file that is created.
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.
The namespaces for the classes should all be “Employee”, but you should verify that the namespaces for all the classes are the same.
Update the program information in the ApplicationUtilities.DisplayApplicationInformation method to reflect your name, current lab, and program description.
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:
Add the constants to the class using the following as an example:
public const double MIN_SALARY = 20000;
In the default constructor, update assignment statements to use the defined constants
Change all the employee class attributes to private.
Create a private static numEmployees variable and initialize it to zero
Increment numEmployees by 1 in each of the constructors
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.
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.
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:
employee1.FirstName = “John”
To get the full name, the statement would look look something like:
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.
Display the program information.
Create an Employee object using the default constructor.
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.
Display the employee information.
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.
Display the Employee information for the second employee object.
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).
After the first employee information is provided, display the number of employees created.
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.
Create a third Employee object using the parameterized constructor setting each of the attributes with the following values: “Sue”, “Smith”, „F‟, 15, 500000.0
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.
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.
SCREENSHOTS
SOLUTION
PAYMENT
The solution includes a Visual Studio (c#) project
Attachments [Move over files to preview content of those files]
CIS247A_iLab_3.zip (119.09 KB)
CIS247A-Lab-3-Screenshot.png
Visual Studio project
CIS247_WK3_Lab
CIS247_WK3_Lab
App.config
ApplicationUtilities.cs
bin
Debug
CIS247_WK3_Lab.exe
CIS247_WK3_Lab.exe.config
CIS247_WK3_Lab.pdb
CIS247_WK3_Lab.vshost.exe
CIS247_WK3_Lab.vshost.exe.config
CIS247_WK3_Lab.vshost.exe.manifest
CIS247_WK3_Lab.csproj
Employee.cs
InputUtilities.cs
obj
Debug
CIS247_WK3_Lab.csproj.FileListAbsolute.txt
CIS247_WK3_Lab.csprojResolveAssemblyReference.cache
CIS247_WK3_Lab.exe
CIS247_WK3_Lab.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Program.cs
Properties
AssemblyInfo.cs
CIS247_WK3_Lab.sln
CIS247_WK3_Lab.v12.suo
Preview ApplicationUtilities.cs
xxxxx xxxxxx;
xxxxx xxxxxx.xxxxxxxxxxx.xxxxxxx;
xxxxx xxxxxx.xxxx;
xxxxx xxxxxx.xxxx;
xxxxx xxxxxx.xxxxxxxxx.xxxxx;
namespace CIS247_WK3_Lab { public class ApplicationUtilities { public static void DisplayApplicationInformation() {
xxxxxxx.xxxxxxxxx(“xxxxxxx xxx xxxxx xxxxxxxx xxxxxxx”);
xxxxxxx.xxxxxxxxx(“xxx247x, xxxx 3 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();
}
Preview Employee.cs
xxxxxxx xxxxxx xxxxxxxxx; //xxxxx xxxx xx xxx xxxxxxxx
xxxxxxx xxxxxx xxxxxxxx; //xxxx xxxx xx xxx xxxxxxxx
xxxxxxx xxxx xxxxxx; //xxxxxx xx xxx xxxxxxxx
xxxxxxx xxx xxxxxxxxxx; //xxxxxxxxx xx xxx xxxxxxxx
xxxxxxx xxxxxx xxxxxxxxxxxx; //xxxxxx xxxxxx xx xxx xxxxxxxx
private const int MIN_DEPENDENTS = 0; //Default value for min dependants private const int MAX_DEPENDENTS = 10; //Default value for max dependants private const double MIN_SALARY = 20000; //Default value for min salary private const double MAX_SALARY = 100000; //Default value for max salary private const string DEFAULT_NAME = “not given”; //Default value for name private const char DEFAULT_GENDER = ‘U’; //Default value for gender
private static int numEmployees = 0; //Counter variablefor employee objects created so far
public static int NumberEmployees //Function to get value of static variable numEmployees {
xxx //xxxxxx xxx xxxxxxxxxxxx
{
xxxxxx xxxxxxxxxxxx;
}
}
Preview InputUtilities.cs
xxxxxx xxxxxx xxxxxx xxxxxxxx(xxxxxx xxxxxxxxx)
{
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
{
Preview Program.cs
xxxxxx xxxx xxxx(xxxxxx[] xxxx)
{
xxxxxxxx xxxxxxxxxxxxx = xxx xxxxxxxx();
xxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx(); //xxxxxxx xxx xxxxxx xxx xxx xxxxxxxxxxx
ApplicationUtilities.DisplayDivider(“Start Program”); //Show heading that the program has started ApplicationUtilities.DisplayDivider(“Collect Employee Information”); //Heading that shows we are ready to input first employee information firstEmployee.FirstName = InputUtilities.getStringInputValue(“First Name”); //Get first name input from the user firstEmployee.LastName = InputUtilities.getStringInputValue(“Last Name”);//Get last name input from the user firstEmployee.Gender = InputUtilities.getCharInputValue(“Gender”);//Get gender input from the user firstEmployee.Dependents = InputUtilities.getIntegerInputValue(“# Dependents”);//Get dependent input from the user firstEmployee.AnnualSalary = InputUtilities.getDoubleInputValue(“Annual Salary”);//Get annual salary input from the user
Console.WriteLine(“”); Console.Write(firstEmployee.ToString()); //Display first Employee information
ApplicationUtilities.PauseExecution();// create a pause so that user needs to press a key to continue
xxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxx(” xxxxxx xxxxxx xxx “);
xxxxxx xxxxxxxxxxxxx = xxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxx(“xxx xxxxxx xxxxxx”);//xxx xxxxxxx xxxxxx xxxxxx xxxxx xxxx xxx xxxx
xxxxxxx.xxxxxxxxx(xxxxxxxxxxxxx.xxxxxxxxx + ” ” + xxxxxxxxxxxxx.xxxxxxxx + ” xxxxxxxx xxxxxx xxx: ” + xxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxx(xxxxxxxxxxxxx).xxxxxxxx(“x2”));
xxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxx();// xxxxxx x xxxxx xx xxxx xxxx xxxxx xx xxxxx x xxx xx xxxxxxxx
Price: $12
$15
Save $3 (20%)
Buy Now
Checkout
Added to cart
Add to Cart
Checkout
Added to cart
Note: We offer a discount for buyers who purchase multiple items.
You May Also Like:
CIS247A Week 1 iLab Creating a User Interface
CIS247A Week 2 iLab Object Construction and Data Abstraction
CIS247A Week 4 iLab Composition and Class Interfaces
CIS247A Week 5 iLab Composition Inheritance and Polymorphism
CIS247A Week 6 iLab Abstract Classes
CIS247A Week 7 iLab Putting It All Together

Reviews

There are no reviews yet.

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