Question

Objectives:The focus of this assignment is to create and use a recursive method given a moderately...

Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem.

Program Description:

This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm.

A total of seven classes are required.

Employee (From previous assignment)

HourlyEmployee (From previous assignment)

SalaryEmployee (From previous assignment)

CommissionEmployee (From previous assignment)

EmployeeManager (Altered from previous assignment)

EmployeeDriver (Altered from previous assignment, provided)

InvalidCharacterException (provided)

Required changes to Employee Manager in bold

EmployeeManager

EmployeeManager

- employees : Employee[]

- employeeMax : final int = 10

-currentEmployees : int

<<constructor>> EmployeeManager

+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double)

+ 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

Data Members

-       Employee[] employees – Collection of Employee objects

-       final int employeeMax = 10 – Maximum number of Employees allowed

-       int currentEmployees – Current number of Employees in collection

Methods

public EmployeeManager()

Constructor, creates the Employee array, sets currentEmployees to 0.

public void addEmployee(int, String, String, char, char, int, Boolean, double)

Takes an int representing the type of Employee to be added (1 – Hourly, 2 – Salary, 3 – Commission) as well as the required data to create that Employee. If one of these values is not passed output the line, “Invalid Employee Type, None Added”, and exit the method. If an Employee with the given Employee Number already exists do not add the Employee and output the line, “Duplicate Not Added”, and exit the method. If the array is at maximum capacity do not add the new Employee, and output the line, "Cannot add more Employees".

public void removeEmployee(int)

Removes an Employee located at the given index from the Employee array.

public void listAll()

Lists all the current Employees. Outputs there are none if there are none.

public void listHourly()

Lists all the current HourlyEmployees. Outputs there are none if there are none.

public void listSalary()

Lists all the current SalaryEmployees. Outputs there are none if there are none.

public void listCommission()

Lists all the current CommissionEmployees. Outputs there are none if there are none.

public void resetWeek()

Resets the week for all Employees.

public double calculatePayout()

Returns the total weekly payout for all Employees.

public int getIndex(int)

Given an Employee Number, returns the index of that Employee in the array, if the Employee doesn’t exist retuns -1.

public void annualRaises()

Applies annual raise to all current Employees.

public double holidayBonuses()

Outputs and returns the total holiday bonus of all Employees.

public void increaseHours(int, double)

Increase the hours worked of the Employee at the given index by the given double amount.

public void increaseSales(int, double)

Increase the sales of the Employee at the given index by the given double amount.

public Employee[] findAllBySubstring(String find)

This method will return an array of all the Employees in the EmployeeManager that contain the substring passed. Create a new Employee array with the size of the number of current Employees. For every Employee call upon the RabinKarp method giving the search string as the concatenation of that Employee’s first and last name (no spaces). If the substring is found in the Employee add that Employee to the new array. After all have been checked, return the array.

private int charNumericValue(char c)

Given a character, returns the numeric value of the character, starting with A – 0 up to Z – 25. This should treat upper and lower case the same; that is passing it ‘A’ will return 0, passing it ‘a’ will also return 0. If a letter is not passed this method should create and throw an InvalidCharacterException as provided.

private int stringHash(String s)

Given a string, return the hash value of the entire String. Use a base 26 number system to create the hash as described in class. This will be needed only to find the hash of the substring that is being searched for and the base case for finding all substring hashes in the search string.

private int RabinKarpHashes(String s, int[] hashes, int pos, int length)

Finds the hash values of all substrings of size length in the String s, starting at index pos and down. These values are stored in the passed hashes array. This method must be recursive, using the technique as described in the Rabin-Karp lecture.

private int linearSearchRecursive(int[] data, int key, int pos)

This is a recursive linear search. Return the position of key in the data array, or -1 if it is not present. This method must be recursive.

private int RabinKarp(String name, String find)

Does the preprocessing of finding the hash for the substring, find using the stringHash method and the hashes of substrings in the search string using RabinKarpHashes method. Calls upon linearSearchRecursive to determine if the substring hash is in the collection of hashes and returns the result.

Other Notes:

·         Classes from the previous assignment will retain the same package structure. The new Exception is declared to be in its own package called “exceptions”.

·         Your EmployeeManager must import the InvalidCharacterException in order to use it

·         Compile using: javac –d . *.java

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative sort that sorts the vehicle rentals by color in ascending order (smallest to largest) Create a method to binary search for a vehicle based on a color, that should return the index where the vehicle was found or -1 You are comparing Strings in an object not integers. Ex. If the input is: brown red white blue black -1 the output is: Enter the...
IN JAVA: Write recursive method to return true if a given array has element equal to...
IN JAVA: Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp,...
Write recursive method to return true if a given array has element equal to employee emp,...
Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp, and returns...
Write recursive method to return true if a given array of integers, named numbers, with n...
Write recursive method to return true if a given array of integers, named numbers, with n occupied positions is sorted in ascending (increasing) order, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary. // An empty array and an array with single element in it, are sorted. Method isSortedRec must be recursive and returns...
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A...
This assignment is an individual assignment. For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B()...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
) IN JAVA: Write a recursive method lowestPaidEmployeeRec that is placed in the linked list after...
) IN JAVA: Write a recursive method lowestPaidEmployeeRec that is placed in the linked list after the method countHighEarners. Method returns employee with lowest salary in entire linked lists of employees. Assume the same LinkedList class as is given as in question 10 above. // PRECONDITION: Linked list is not empty. public Employee lowestPaidEmployeeRec(Node first) // first is reference to the beginning of linked list. { }
Hello. I have an assignment that is completed minus one thing, I can't get the resize...
Hello. I have an assignment that is completed minus one thing, I can't get the resize method in Circle class to actually resize the circle in my TestCircle claass. Can someone look and fix it? I would appreciate it! If you dont mind leaving acomment either in the answer or just // in the code on what I'm doing wrong to cause it to not work. That's all I've got. Just a simple revision and edit to make the resize...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text...
Step 1: Edit StringExplode.java Download the StringExplode.java file, and open it in jGrasp (or a text editor of your choice). This program will “explode” a String into an array of characters (char[]), and then print out the array. The String comes from the first command-line argument. Example output with the command-line argument foo is below: f o o --------------------------------------------------------------------- public class StringExplode { // TODO - write your code below this comment. // You will need to write a method...