C# Programming

profiledmpiney198x
wk2.zip

wk2/utility classes.zip

ApplicationUtilities.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CIS247A_Employee { public class ApplicationUtilities { public static void DisplayApplicationInformation() { Console.WriteLine("Welcome the Basic Employee Program"); Console.WriteLine("CIS247a, Week 2 Lab"); Console.WriteLine("Name: Tevis Boulware"); Console.WriteLine("This program accepts user input as a string, then makes the \nappropriate data conversion and assigns the value to Employee objects"); Console.WriteLine(); } public static void DisplayDivider(string outputTitle) { Console.WriteLine("\n********* " + outputTitle + " *********\n"); } public static void TerminateApplication() { DisplayDivider("Program Termination"); Console.Write("Thank you. Press any key to terminate the program..."); Console.ReadLine(); } public static void PauseExecution() { Console.Write("\nProgram paused, press any key to continue..."); Console.ReadLine(); Console.WriteLine(); } } }

InputUtilities.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CIS247A_Employee { public class InputUtilities { public static string GetInput(string inputType) { string strInput = String.Empty; Console.Write("Enter the " + inputType + ": "); strInput = Console.ReadLine(); 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)) { value = inputString; valid = true; } else { value = "Invalid input"; valid = false; } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } public static int getIntegerInputValue(string inputType) { bool valid = false; int value = 0; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!(String.IsNullOrEmpty(inputString))) { valid = Int32.TryParse(inputString, out value); } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } public static double getDoubleInputValue(string inputType) { bool valid = false; double value = 0; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!(String.IsNullOrEmpty(inputString))) { valid = Double.TryParse(inputString, out value); } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } public static char getCharInputValue(string inputType) { bool valid = false; char value = 'u'; string inputString = String.Empty; do { inputString = GetInput(inputType); if (!(String.IsNullOrEmpty(inputString))) { valid = Char.TryParse(inputString, out value); } if (!valid) Console.WriteLine("Invalid " + inputType + " try again!"); } while (!valid); return value; } } }

wk2/wk2.docx

1. Download the Utility Classes file, which is a zip file that contains two classes (1) ApplicationUtilities.cs and (2) InputUtilities.cs. Unzip the two files and place the files in a known location.

2. Create a new project called "CIS247_WK2_Lab_LASTNAME". An empty project will then be created.

3. Right click the project name in the Solution Explorer, or select the Project Menu, and select "Add Existing Item"

4. Navigate to the folder where you saved the (1) ApplicationUtilities.cs and (2) InputUtilities.cs class files, select the files, and then click add.

5. The files will be added to your project.

6. The final step is to change the name of the Namespace so all the classes in the project can recognize each other (there are advanced ways around this, but for this course may be easiest to change the namespace. In order to make it easier for the follow on weeks, change the namespace to all the classes to "Employee". The file list in the Solution Explorer will then look something like:

Since all the lab assignments through the rest of the course will re-use classes from the previous week's assignments, make sure you become proficient in adding existing items--it will reduce the amount of "busy work" you have to do each week!

STEP 3: Code the Employee class

Back to Top

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 provided Class Diagram as a guide code the Employee class in the new project (i.e., "Realize the UML Class diagram").

1. Add a new class called "Employee" to the project

2. Create private variables and correctly initialize them for the Employee class attributes.

3. Create constants in the Employee class for the default values, and the default constuctor shall set these default values to the appropriate attribute.

4. The multi-argument constructor (parameterized constructor) should initialize all of the attributes using values passed in through the parameter list.

5. As mentioned above, for this lab ONLY will the attributes be made "public" and we will access the attributes directly. Begininning in Week 3 ALL variable attributes of every class will be private and access will be done through the get and set methods.

6. The CalculateWeeklyPay( ) method of the Employee class should return the value of annual salary divided by 52 (return annualSalary / 52;).

7. Most classes will have a ToString method that collects the key class attributes into a single well formated string. The method will always be declared using the "override" keyword (this will be explained in Week 5) and the declaration of the ToString method for every class will look like the following: public override string ToString()

8. The ToString method will always return a string value that collects the key attributes, the following shows one technique that you can use to collect the information and return the formatted string: public override string ToString() { string output; output = "============ Employee Information ============"; output += "Name: " + firstName + " " + lastName; //rest of method omitted return output; }

9. In order to print out currency values in currency format (dollars and cents) you can use the ToString method that each numeric variable has predefined. For example, to output the annualSalary in currency you would use the following: output += "Annual Salary: " + AnnualSalary.ToString("C2");

STEP 4: Code the Main Program

Back to Top

In the Main class, create code statements that perform the following operations.

Remember, to access a public method (method or property) of an object, or class, use the DOT notation:

objectName.MethodName()

For example, to access the DisplayApplicationInformation of the ApplicationUtilities class, the statement would look something like:

ApplicationUtilities.DisplayApplicationInformation();

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

STEP 5: Compile and Test

Back to Top

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.

Image Description

On-screen output display:

*********************** Employee Information ********************** First Name: John Last Name: Doe Gender: M Dependents: 3 Annual Salary: $46,000.00 Weekly Pay: $884.62 *********************** Employee Information ********************** First Name: Sue Last Name: Smith Gender: F Dependents: 3 Annual Salary: $52,000.00 Weekly Pay: $1,000.00

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

STEP 6: Submit Deliverables

Back to Top

· Capture the Console output window and paste it into a Word Document.

· Put the zip file of you project folder and screen shots (Word document) in the Dropbox.