Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i L A B S T E P S STEP 1: Understand the UML Diagram Employee - firstName : stri

ID: 3640370 • Letter: I

Question

i L A B S T E P S
STEP 1: Understand the UML Diagram




Employee - firstName : string - lastName : string - gender : char - dependents : int - annualSalary : double - static numEmployees : int = 0 +Employee() +Employee(in first : String, in last : String, in gen : char, in dep : int, in sal : double) +calculatePay() : double +displayEmployee() : void +static getNumEmployees() : int +getFirstName() : String +setFirstName(in first : String) : void +getLastName() : String +setLastName(in last : String) : void +getGender() : char +setGender(in gen : char) : void +getDependents() : int +setDependents(in dep : int) : void +getAnnualSalary() : double +setAnnualSalary(in salary : double) : void +setAnnualSalary(in salary : String) : void The following attribute has been added:

- static numEmployees: int = 0
The following behaviors have been added:

+ static getNumEmployees( ) : int
+ setDependents(in dep : String) : void
+ setAnnualSalary(in sal : String) : void
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:

Open the same workspace you created for the Week 2 project.
Create a new project named "CIS247B_WK3_Lab_LASTNAME". An empty project will then be created.
Copy your main class and employee class files from Week 2 and paste them into the Week 3 project.
Before you move on to the next step, build and execute the Week 3 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


Using the UML Diagrams from Step 1, code the changes to the Employee class.

Create a static numEmployees variable and initialize it to zero.
Increment numEmployees by 1 in each of the constructors.
Create an overloaded setDependents method and, this time, make the parameter a string.
Create an overloaded setAnnualSalary method and, this time, make the parameter a string.
Remember that you will have to convert the string in the above two "set" methods to the data type of the attribute.
Make the getNumEmployees a static method. (This way, you can call it with the class name instead of an object name.)
Be sure you follow proper commenting and programming styles (indentation, line spacing, etc.).

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.). Note that several of the steps below were accomplished in last week's assignment. New steps are in bold.

Create an Employee object using the default constructor.
Prompt for and then set the first name, last name, and gender. Consider using your getInput method from Week 1 to obtain data from the user for this step as well as Step 3.
Prompt for and then set dependents and annual salary using the new overloaded setters.
Using your code from Week 1, display a divider that contains the string "Employee Information".
Display the Employee Information.
Display the number of employees created using getNumEmployees. Remember to access getNumEmployees using the class name, not the Employee object.
Create a second Employee object using the multi-arg constructor, setting each of the attributes with the following values: "Mary", "Noia", 'F', 5, 24000.0
Using your code from Week 1, display a divider that contains the string "Employee Information".
Display the employee information for the second Employee object.
Display the number of employees created using getNumEmployees. Remember to access getNumEmployees using the class name, not the Employee object.
STEP 5: Compile and Test


When done, compile and run your code. 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:



Screenshot of program that reads: ************** Employee Information ************** First Name: John Last Name: Doe Gender: M Dependents: 7 Annual Salary: $32,500.00 Weekly Pay: $625.00 Total employees: 1 *************** Employee Information *************** First Name: Mary Last Name: Noia Gender: F Dependents: 5 Annual Salary: $24,000.00 Weekly Pay: $461.54 Total employees: 2

Explanation / Answer

public class Employee { public static String FIELD_NAME_ID = "id"; public static String FIELD_NAME_EMPLOYEE_ID = "employeeId"; public static String FIELD_NAME_NAME = "name"; public static String FIELD_NAME_TYPE = "employeeType"; public static String FIELD_NAME_SALARY_TYPE = "salaryType"; public static String FIELD_NAME_SALARY = "salary"; public static String FIELD_NAME_STATUS = "status"; public static String FIELD_NAME_JOIN_DATE = "joinDate"; public static String FIELD_NAME_LEAVE_DATE = "leaveDate"; public static String[] colTexts = new String[]{"??", "", "", "?", "", "", "??", "", "?"}; public static String[] colNames = new String[]{FIELD_NAME_ID, FIELD_NAME_EMPLOYEE_ID, FIELD_NAME_NAME, FIELD_NAME_TYPE, FIELD_NAME_SALARY_TYPE, FIELD_NAME_SALARY, FIELD_NAME_STATUS, FIELD_NAME_JOIN_DATE, FIELD_NAME_LEAVE_DATE}; /** û?? **/ public static String TYPE_WAITER = "1"; public static String TYPE_CASHER = "2"; public static String TYPE_MANAGER = "3"; public static String TYPE_ADMIN = "4"; public static String TYPE_KITCHEN = "5"; public static String SALARY_TYPE_HOUR = "1"; public static String SALARY_TYPE_DAY = "2"; public static String SALARY_TYPE_MONTH = "3"; public static String STATUS_WORK = "1"; public static String STATUS_RETIRE = "2"; private long id; private String employeeId; private String name; private String salaryType; private double salary; private String status; private Date joinDate; private Date leaveDate; private EmployeeType employeeType; /** * ???i * @param name * @return ?i */ public static String getText(String name){ if(name==null||"".equals(name)) return ""; for(int i=0;i