I just need help with the employee and employeemanager classes described in the
ID: 3777199 • Letter: I
Question
I just need help with the employee and employeemanager classes described in the UML Diagrams the other files don't have to be modified but i will provide the uml for the array list and the linked list
Changes to Employee
The Employee class must now implement the Serializable interface in order to be used with Object Serialization
Employee {abstract} implements Comparable<Employee>, Serializable
- String firstName
- String lastName
- char middleInitial
- boolean fulltime
- char gender
- int employeeNum
<<constructor>> Employee (fn : String, ln : String, m : char, g : char, empNum : int, ft : boolean ) throws InvalidEmployeeNumberException
+ getEmployeeNumber() : int
+ setEmployeeNumber(empNum : int)
+ getFirstName() : String
+ getLastName() : String
+ setFirstName(fn: String)
+ setLastName(ln : String)
+ setMiddleI(m : char)
+ setGender(g : char)
+ equals(e2 : Object) : Boolean
+ toString() : String
+ calculateWeeklyPay() : double {abstract}
+ annualRaise() {abstract}
+ holidayBonus() : double {abstract}
+ resetWeek() {abstract}
+ compareTo(Employee e)
Changes to EmployeeManager
The EmployeeManager will now be able to save and load the Employees from session to session using Serialized files. It will also be able to process text files to quickly update multiple Employees.
EmployeeManager
- employees : ArrayList<Employee>
- employeeMax : final int = 10
- hourlyList : LinkedList<Employee>
- salaryList : LinkedList<Employee>
- commissionList : LinkedList<Employee>
- vacationRequests : Queue<Employee>
<<constructor>> EmployeeManager()
+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) throws InvalidEmployeeNumberException
+ removeEmployee( index : int)
+ listAll()
+ listHourly()
+ listSalary()
+ listCommision()
+ resetWeek()
+ calculatePayout() : double
+ getIndex( empNum : int ) : int
+ annualRaises()
+ holidayBonuses() : double
+ increaseHours( index : int, amount : double)
+ increaseSales( index : int, amount : double)
+ findAllBySubstring(find : String) : Employee[]
- RabinKarp(name : String, find : String) : int
- stringHash(s : String) : int
- charNumericValue(c : char) : int
- RabinKarpHashes(s : String, hashes : int[], pos : int, length : int) : int
- linearSearchRecursive(nameHashes : int[], findHash : int, pos : int) : int
+ sort()
+ addRequest(empNum : int) : boolean
+ viewNextRequest() : Employee
+ grantNextRequest() : Employee
+ outputRequests()
+ loadEmployees(employeeFile : String, requestFile : String) boolean
+saveEmployees(employeeFile : String, requestFile : String) boolean
+processUpdates(fileName : String) boolean
public boolean loadEmployees(String employeeFile, String requestFile)
Given the name of a serialized file (employeeFile), this method attempts to read in Employees from a previous session. This method will return true if the load of Employees was successful and false if it was not successful (file doesn’t exist, ClassNotFoundException, or other IOException). Before reading in the Employees it will clear all of the lists to ensure it is loading into an empty set of Employees. This includes the ArrayList, the LinkedLists, and the Queue. If a MaximumCapacityException is encountered while adding Employees output “Maximum Capacity Reached”, and return true. The method will also open the text file (requestFile) to rebuild the vacation request Queue.
public boolean saveEmployees(String employeeFile, String requestFile)
This method will store all of the Employees as Serialized objects in the employeeFile and the Employee numbers in the correct order of those in the vacation Queue as plain text, placing a new line after every number.
public boolean processUpdates(String fileName)
Given the name of a text file, this method will process the update requests within the file. A valid update request is in the form:
EMPLOYEE_NUMBER AMOUNT
Where the two values are separated by a space. Employee numbers are ints, amount can be a double. It will skip updates with a negative amount. If an improperly formatted update request is reached it will skip that update and proceed to the next update.
To correctly apply an update you must call upon either increaseHours or increaseSales method of the EmployeeManager, depending on the type of employee that has the given Employee number. Employee numbers that do not exist or Employee numbers of SalaryEmployees are skipped.
Linked List & ListNode
ListNode<E extends Comparable<E>>
- data : E
- nextNode: ListNode<E>
<<constructor>>ListNode(d : E)
<<constructor>>ListNode(d : E, node : ListNode<E>)
+ setData(d : E)
+getData() : E
+setNext(next : ListNode<E>)
+getNext() : ListNode<E>
Notes on ListNode
ListNode(d : E) sets the nextNode to null, the rest of the implementation of the ListNode class is self-explanatory as discussed in class
UML DIAGRAM FOR AND DISCUSSION FOR LinkedList
LinkedList<E extends Comparable<E>>
- firstNode : ListNode<E>
- lastNode : ListNode<E>
- numElements : int
- name : String
<<constructor>>LinkedList()
<<constructor>>LinkedList(name : String)
+ insertAtFront(item : E)
+ insertAtBack(item : E)
+ removeFromFront() : E throws EmptyListException
+ removeFromBack() : E throws EmptyListException
+ removeItem(index : int) : E throws IndexOutOfBoundsException
+ getItem(index : int) : E throws IndexOutOfBoundsException
+ setItem(index : int, item : E) throws IndexOutOfBoundsException
+ findAndRemove(item : E) : Boolean
+ findItem(item E) : int
+ lengthIs() : int
+ clear()
+ toString()
+ isEmpty() : Boolean
+ sort() throws EmptyListException
Array List
ArrayList<E extends Comparable<E>>
- DEFCAP : int final = 50
- origCap : int
- numElements : int
- list : Object[]
<<constructor>>ArrayList()
<<constructor>>ArrayList(size : int) throws InvalidSizeException
+ addItem(item : E) throws MaximumCapacityException
+ getItem(index int) : E throws IndexOutOfBoundsException
+ setItem(index int, item E) throws IndexOutOfBoundsException
+ removeItem(index int) : E throws IndexOutOfBoundsException
+ findItem(item E) : int
+ isEmpty() : Boolean
+ lengthIs() : int
+ clear()
+ toString() : String
+ sort()
- enlarge() throws MaximumCapacityException
Notes on ArrayList
The ArrayList class implements an ArrayList data structure, capable of handling types that implement Comparable<E>. The logic for most of the methods was covered in class, you’ll have to convert these to take advantage of the Generic type that is passed.
Constructors
The constructor that takes no size will set the origCap to DEFCAP and this will be the initial size.
The constructor that accepts a size parameter must throw an InvalidSizeException if the size passed is greater than the DEFCAP or less than 1.
Methods
public void addItem(E item) throws MaximumCapacityException
Attempts to add a new item to the ArrayList. If the array is at capacity it attempts to enlarge, then adds the item to the end.
public E getItem(int index)
This method is to retrieve an item in the list given an index into the ArrayList. If that index does not exist within the ArrayList an IndexOutOfBoundsException is thrown with the message: “Index out of Range”.
public setItem(int index, E item)
Attempts to place the passed item into the given index. If that index does not exist within the ArrayList an IndexOutOfBoundsException is thrown with the message: “Index out of Range”.
public E removeItem(int index)
Attempts to remove the item at the given index from the ArrayList. If that index does not exist within the ArrayList an IndexOutOfBoundsException is thrown with the message: “Index out of Range”.
public int findItem(E item)
Performs a linear search to fine the item passed. Returns the index of the item if found, returns -1 if not found.
public Boolean isEmpty()
Returns a true if the ArrayList is empty, otherwise false.
public int lengthIs()
Returns the current number of elements in the ArrayList.
public void clear()
Clears contents of the ArrayList, sets size of array to the original capacity.
public String toString()
Returns a String containing all elements in the ArrayList, separated by a new line.
public void sort()
Sorts the contents of the ArrayList using the Insertion Sort.
private void enlarge()
Will attempt to enlarge the ArrayList by the value of origCap. If this would put it past its maximum size defined by DEFCAP it will enlarge to the size of DEFCAP. If it is already at size of DEFCAP it will throw a MaximumCapacityException.
Employee {abstract} implements Comparable<Employee>, Serializable
- String firstName
- String lastName
- char middleInitial
- boolean fulltime
- char gender
- int employeeNum
<<constructor>> Employee (fn : String, ln : String, m : char, g : char, empNum : int, ft : boolean ) throws InvalidEmployeeNumberException
+ getEmployeeNumber() : int
+ setEmployeeNumber(empNum : int)
+ getFirstName() : String
+ getLastName() : String
+ setFirstName(fn: String)
+ setLastName(ln : String)
+ setMiddleI(m : char)
+ setGender(g : char)
+ equals(e2 : Object) : Boolean
+ toString() : String
+ calculateWeeklyPay() : double {abstract}
+ annualRaise() {abstract}
+ holidayBonus() : double {abstract}
+ resetWeek() {abstract}
+ compareTo(Employee e)
Explanation / Answer
import java.util.*;
public class ManagerTest
{ public static void main (String[] args)
{ Employee[] staff = new Employee[3];
staff[0] = new Employee("varun", 2000000,
1, 10, 1989);
staff[1] = new Manager("arun", 2500000, 1,
12, 1991);
staff[2] = new Employee("vijay", 3000000, 1,
11, 1993);
int i;
for (i = 0; i < 3; i++) staff[i].raiseSalary(5);
for (i = 0; i < 3; i++) staff[i].print();
}}
class Employee
{ public Employee(String n, double s, int day,
int month, int year)
{ name = n;
salary = s;
hireday = day;
hiremonth = month;
hireyear = year;
}
public void print()
{ System.out.println(name + " " + salary + " "
+ hireYear());
}
public void raiseSalary(double byPercent)
{ salary *= 1 + byPercent / 100;
}
public int hireYear()
{ return hireyear;
}
private String name;
private double salary;
private int hireday;
private int hiremonth;
private int hireyear;
}
class Manager extends Employee
{ public Manager (String n, double s,
int d, int m, int y)
{ super(n, s, d, m, y);
secretaryName = "";
}
public void raiseSalary(double byPercent)
{ // add 1/2% bonus for every year of service
GregorianCalendar todaysDate =
new GregorianCalendar();
int currentYear = todaysDate.get(Calendar.YEAR);
double bonus = 0.5 * (currentYear - hireYear());
super.raiseSalary(byPercent + bonus);
}
public String getSecretaryName()
{ return secretaryName;
}
private String secretaryName;
}