I need help with this two methods in java. Here are the guidelines. The methods private int
stringHash(String s) and private int RabinKarpHashes(String s, int[] hashes, int pos, int length).
EmployeeManager
EmployeeManager
- employees : Employee[]
- employeeMax : final int = 10
-currentEmployees : int
<> 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
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.
publi.
I need help with this two methods in java. Here are the guidelines. .pdf
1. I need help with this two methods in java. Here are the guidelines. The methods private int
stringHash(String s) and private int RabinKarpHashes(String s, int[] hashes, int pos, int length).
EmployeeManager
EmployeeManager
- employees : Employee[]
- employeeMax : final int = 10
-currentEmployees : int
<> 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
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
2. 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’
3. 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.
EmployeeManager
- employees : Employee[]
- employeeMax : final int = 10
-currentEmployees : int
<> 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)
5. {
employees = new ArrayList(3);
}
catch (InvalidSizeException E)
{
try
{
employees = new ArrayList(employeeMax);
}
catch (InvalidSizeException e)
{
}
}
hourlyList = new LinkedList();
salaryList = new LinkedList();
commissionList = new LinkedList();
vacationRequests = new Queue();
}
// Method: addEmployee
// Parameters: type,fn, ln, m, g, en, ft, amount
// Returns: none
// Partners: none
// Method uses variables to decide type of employee
public void addEmployee(int type, String fn, String ln, char m, char g, int en, boolean ft,
double amount) throws InvalidEmployeeNumberException
{
if (type == 1)
{
HourlyEmployee E = new HourlyEmployee (fn,ln,m,g,en,ft,amount);
try
{
employees.addItem(E);
hourlyList.insertAtBack(E);
}
catch (MaximumCapacityException e)
6. {
System.out.print("too large");
}
}
if (type == 2)
{
SalaryEmployee E = new SalaryEmployee (fn,ln,m,g,en,ft,amount);
try
{
employees.addItem(E);
salaryList.insertAtBack(E);
}
catch (MaximumCapacityException e)
{
System.out.print("too large");
}
}
if (type == 3)
{
CommissionEmployee E = new CommissionEmployee (fn,ln,m,g,en,ft,amount);
try
{
employees.addItem(E);
commissionList.insertAtBack(E);
}
catch (MaximumCapacityException e)
{
System.out.print("too large");
}
}
}
// Method: removeEmployee
// Parameters: index
// Returns: none
// Partners: CLC
// Method removes a certain employee
7. public void removeEmployee(int index)
{
if(index != -1)
employees.removeItem(index);
}
// Method: listAll
// Parameters: none
// Returns: none
// Partners: none
// Method lists all employees
public String listAll()
{
String x = "";
if(employees.isEmpty() == true)
return "No Employees";
else
return x + employees.toString();
}
// Method: listHourly
// Parameters: none
// Returns: none
// Partners: none
// Method lists all hourly employees
public String listHourly()
{
String a = "";
for (int x = 0; x < hourlyList.lengthIs(); x++)
{
if (hourlyList.isEmpty() == true)
return "No Hourly Employees";
else if (hourlyList.getItem(x) instanceof HourlyEmployee)
{
return a + hourlyList.toString() + " ";
8. }
}
return null;
}
// Method: listSalary
// Parameters: none
// Returns: none
// Partners: none
// Method lists all salary employees
public String listSalary()
{
String b = "";
for (int x = 0; x < salaryList.lengthIs(); x++)
{
if(salaryList.isEmpty() == true)
{
return "No Salary Employees";
}
else if (salaryList.getItem(x) instanceof SalaryEmployee)
{
return b + salaryList.toString() + " ";
}
}
return null;
}
// Method: listCommission
// Parameters: none
// Returns: none
// Partners: none
// Method lists all commission employees
public String listCommission()
{
String c = "";
for (int x = 0; x < commissionList.lengthIs(); x++)
9. {
if(commissionList.isEmpty() == true)
{
return "No Commission Employees";
}
else if (commissionList.getItem(x) instanceof CommissionEmployee)
{
return c + commissionList.toString() + " ";
}
}
return null;
}
// Method: resetWeek
// Parameters: none
// Returns: none
// Partners: none
// Method reset
public void resetWeek()
{
for (int a = 0; a < employees.lengthIs(); a++)
{
employees.getItem(a).resetWeek();
}
}
// Method: calculatePayout
// Parameters: none
// Returns: payout
// Partners: none
// Method calculates and returns weekly payout
public double calculatePayout()
{
double payout = 0;
for (int a= 0; a < employees.lengthIs(); a++)
{
payout += employees.getItem(a).calculateWeeklyPay();
}
10. return payout;
}
// Method: getIndex
// Parameters: empNum
// Returns: empNum
// Method retrieves location of employee number
public int getIndex(int empNum)
{
for (int a = 0; a < employees.lengthIs(); a++)
if (empNum == employees.getItem(a).getEmployeeNumber())
return a;
return -1;
}
// Method: annualRaises
// Parameters: none
// Returns: none
// Partners: none
// Method calculates annual raise
public void annualRaises()
{
for (int a = 0; a < employees.lengthIs(); a++)
{
employees.getItem(a).annualRaise();
}
}
// Method: holidayBonuses
// Parameters: none
// Returns: payout
// Partners: none
// Method used to output
public double holidayBonuses()
{
double payout = 0;
for (int a = 0; a < employees.lengthIs(); a++)
11. {
payout += employees.getItem(a).holidayBonus();
//System.out.print (employees.getItem(a).toString());
double b = employees.getItem(a).holidayBonus();
System.out.printf ("Bonus ammount: %.2f", b);
System.out.print (" ");
}
return payout;
}
// Method: increaseHours
// Parameters: index, amount
// Returns: none
// Partners: none
// Method increases a certain employee’s hours worked.
public boolean increaseHours(int index, double amount)
{
for (int x = 0; x < employees.lengthIs(); x++)
{
if (employees.getItem(x) instanceof HourlyEmployee)
{
if (index == ((HourlyEmployee)employees.getItem(x)).getEmployeeNumber())
{
((HourlyEmployee)employees.getItem(x)).increaseHours(amount);
}
else
return false;
}
}
return true;
}
// Method: increaseSales
// Parameters: index, amount
// Returns: none
// Partners: none
// Method increases a certain employee’s sales
public boolean increaseSales(int index, double amount)
12. {
for (int x = 0; x < employees.lengthIs(); x++ )
{
if (employees.getItem(x) instanceof CommissionEmployee)
{
if (index == (
((CommissionEmployee)employees.getItem(x)).getEmployeeNumber()))
{
((CommissionEmployee)employees.getItem(x)).increaseSales(amount);
}
else
return false;
}
}
return true;
}
// Method: findAllBySubString
// Parameters: findt
// Returns: Employee[]
// Method finds substring of string
public ArrayList findAllBySubstring(String find)
{
ArrayList ken = new ArrayList();
int count = 0;
for (int a = 0; a < employees.lengthIs(); a++)
{
if((RabinKarp((employees.getItem(a).getFirstName() +
employees.getItem(a).getLastName()), find)) != -1)
{
try
{
ken.addItem(employees.getItem(a));
}
catch (MaximumCapacityException e)
{
13. System.out.print("too large");
}
}
}
return ken;
}
// Method: RabinKarp
// Parameters: name, find
// Returns: hash
// Method calculates hashes
private int RabinKarp(String name, String find)
{
if (find.length() > name.length())
return -1;
int findHash = stringHash(find);
int [] nameHash = new int [name.length() - find.length() + 1];
String sub = name.substring(0, find.length());
nameHash[0] = stringHash(sub);
RabinKarpHashes(name, nameHash, name.length() - find.length(), find.length());
int x = linearSearchRecursive(nameHash, findHash, name.length() - find.length());
return x;
}
// Method: stringHash
// Parameters: s
// Returns: hash
// Method finds hash of entire string
private int stringHash (String s)
{
int hash = 0;
for(int i = 0; i < s.length(); i++)
{
hash += charNumericValue(s.charAt(i))*Math.pow(26,s.length()-i-1);
}
14. return hash;
}
// Method: charNumericValue
// Parameters: findt
// Returns: c
// Method finds substring of string
private int charNumericValue(char c) throws InvalidCharacterException
{
switch (c)
{
case 'a': case 'A':
return 0;
case 'b': case 'B':
return 1;
case 'c': case 'C':
return 2;
case 'd': case 'D':
return 3;
case 'e': case 'E':
return 4;
case 'f': case 'F':
return 5;
case 'g': case 'G':
return 6;
case 'h': case 'H':
return 7;
case 'i': case 'I':
return 8;
case 'j': case 'J':
return 9;
case 'k': case 'K':
return 10;
case 'l': case 'L':
return 11;
case 'm': case 'M':
15. return 12;
case 'n': case 'N':
return 13;
case 'o': case 'O':
return 14;
case 'p': case 'P':
return 15;
case 'q': case 'Q':
return 16;
case 'r': case 'R':
return 17;
case 's': case 'S':
return 18;
case 't': case 'T':
return 19;
case 'u': case 'U':
return 20;
case 'v': case 'V':
return 21;
case 'w': case 'W':
return 22;
case 'x': case 'X':
return 23;
case 'y': case 'Y':
return 24;
case 'z': case 'Z':
return 25;
}
throw new InvalidCharacterException(c);
}
// Method: RabinKarpHashes
// Parameters: s, hashes, pos, length
// Returns: pos
// Method finds hashaes
private int RabinKarpHashes (String s, int[] hashes, int pos, int length)