Question
USING JAVA CODE THE FOLLOWING: Part 1: Printable Interface Reference the following Printable UML interface below: -Create a new interface called Printable. This interface has
USING JAVA CODE THE FOLLOWING:
Part 1: Printable Interface
Reference the following Printable UML interface below:
-Create a new interface called Printable. This interface has two variables of type NumberFormat. These are variables that allow us to better format everything that can implement the Printable interface. Right now we already have these variables created on the Employee abstract class so we are going to move them around.
-To do this:
-Move the currency and percent NumberFormat variables from the Employee file to the Printable
-We don't need protected or static as the interface takes care of this for us
-Also note the classes that use these NumberFormat will give you an error until we implement it down below
-Make sure to import NumberFormat when doing this (most IDEs should ask you if you want to import it automatically)
-You can then delete the import NumberFormat on the Employee class as we don't use it anymore
Now we have the Printable interface that we can implement on the Employee class. Modify the Employee abstract class header by implementing Printable and EmployeeType. This now gives some errors but also fixes some things.
-The toString() methods on all the classes should not have any errors as they have access to the percent and currency NumberFormat objects
-Now we have an error because we don't have a print() method on any of the classes. We do have a printEmployee() function that does what we want, so instead of creating another print method, rename the printEmployee() to just print(). Doing this in the Employee class makes it so we don't have to do it in each subclass. -This function needs to be overridden.
Part 2: Enumeration Types
Create a new java class of type Enumeration called EmployeeType. Reference the following UML below:
-Create the constants for each employee type.
-Add a toString() method that returns either "Hourly" "Salary" or "Commission"
-Use a switch or if statement to check this.ordinal() seeing if it is 0, 1, or 2 for Hourly, Salary, or Commission respectively
Part 3: Update the Employees.java for the EmployeeType Enumeration
-Now that we have our EmployeeType enum, let's add it into our system. Once again here is the UML Diagram for Employee with updates:
-Make sure to add the variable of type EmployeeType called employeeType.
Constructor Modifications
-In the first and second constructor we need to add another parameter into the list for accepting an EmployeeType. We then take that and assign it to our employeeType variable.
-In the copy constructor you need to assign it using a get method. (get method we are coding below so code it and ignore the error). So it should be something like employeeType = e.getEmployeeType().
-Lastly in the default constructor we are just going to have a default of the HOURLY value. So set employeeType to the EmployeeType.HOURLY.
Getters/Setters
-We need both a getter and setter for our new employeeType variables
toString()
-Lastly we are going to add in to the end of our toString() method so that it prints
To do this we just need to call the employeeType.toString() that you set up earlier.
Employee.java to modify:
public class Employee { private String firstName; private String lastName; private int employeeNum; private String department; private String jobTitle; public Employee(String fn, String ln, int en, String dept, String job) { firstName = fn; lastName = ln; employeeNum = en; department = dept; jobTitle = job; } public String toString() { String str = "Name: " + firstName + " " + lastName + " "; str += "ID: " + employeeNum + " "; str += "Department: " + department + " "; str += "Title: " + jobTitle + " "; return str; } public String getFirstName() { return firstName;} public String getLastName() { return lastName;} public int getEmployeeNumber() { return employeeNum;} public String getDepartment() { return department;} public String getJobTitle() { return jobTitle;} public void setFirstName(String firstN) { firstName = firstN;} public void setLastName(String lastN) { lastName = lastN;} public void setEmployeeNumber(int empNum) { employeeNum = empNum;} public void setDepartment(String depart) { department = depart;} public void setJobTitle(String jbTitle) { jobTitle = jbTitle;} void printEmployee() { System.out.println("Name: " + firstName + " " + lastName); System.out.println("ID: " + employeeNum); System.out.println("Department: " + department); System.out.println("Title: " + jobTitle); } Employee(String firstN, String lastN, int empNum, String depart, String jbTitle, double payRt) { firstName = firstN; lastName = lastN; employeeNum = empNum; department = depart; jobTitle = jbTitle; } }
\begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{> Printable } \\ \hline currency : NumberFormat \\ percent : NumberFormat \\ \hline print() : void \\ \hline \end{tabular} \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{ >EmployeeType } \\ \hline HOURLY \\ SALARY \\ COMMISSION \\ \hline toString(): String \\ \hline \end{tabular} abstract Employee.java implements Printable -firstName : String -lastName : String -employeeNum : int -department : String -jobTitle : String -employeeType : EmployeeType > Employee(String fn, String In, int en, String dept, String job, EmployeeType et) > Employee(String fn, String In, int en, EmployeeType et) > Employee(Employee e) > Employee() +getFirstName() : String +setFirstName(String fn) : void +getLastName() : String +setLastName(String In) : void +getEmployeeNumber() : int +setEmployeeNumber(int en) : void +getDepartment () : String +setDepartment(String dept) : void +getJobTitle() : String +setJobTitle(String job) : void +getEmployeeType() : EmployeeType +setEmployeeType(EmployeeType et) : void +print() : void +abstract resetWeek() : void +abstract calculateWeeklyPar() : double +abstract annualRaise() : void +abstract holidayBonus() : void +abstract setPay(double pay) : void +toString() : String +equals(Object obj2) : boolean Type: \{employeeType\}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started