SlideShare a Scribd company logo
1 of 25
Download to read offline
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.
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.
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
Solution
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.lang.SecurityException;
import java.util.NoSuchElementException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Formatter;
import java.util.FormatterClosedException;
@SuppressWarnings("unchecked")
public class EmployeeManager
{
private ArrayList employees;
private final int employeeMax = 10;
private LinkedList hourlyList;
private LinkedList salaryList;
private LinkedList commissionList;
private Queue vacationRequests;
public EmployeeManager()
{
try
{
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)
{
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
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() + " ";
}
}
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++)
{
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();
}
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++)
{
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)
{
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)
{
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);
}
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':
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)
{
if (pos == 0)
{
hashes[pos] = stringHash(s.substring(pos, pos + length));
}
if (pos > 0)
{
hashes[pos] = 26 * (RabinKarpHashes (s,hashes,pos-1, length) - (charNumericValue
(s.charAt(pos-1)) * (int)Math.pow(26,length-1))) + charNumericValue(s.charAt(pos+length-1));
}
return hashes[pos];
}
// Method: linearSearchRecursive
// Parameters: find
// Returns: pos
// Method does recursivelinear search
private int linearSearchRecursive(int[] data, int key, int pos)
{
if (pos < 0)
{
return -1;
}
if (key == data[pos])
{
return pos;
}
return linearSearchRecursive(data, key, pos-1);
}
// Method: sort
// Parameters: none
// Returns: pos
// Method sorts lists
public void sort()
{
hourlyList.sort();
salaryList.sort();
commissionList.sort();
}
// Method: addRequest
// Parameters: empNum
// Returns: none
// Method does adds request for vacation
public boolean addRequest(int empNum)
{
if (empNum >= 10000 && empNum <= 99999)
{
vacationRequests.enqueue(employees.getItem(getIndex(empNum)));
return true;
}
else
return false;
}
// Method: viewextRequest
// Parameters: none
// Returns: Employee
// Method views next request
public Employee viewNextRequest()
{
Employee emu = null;
if (vacationRequests == null)
return null;
else
return emu;
}
// Method: grantNextRequest
// Parameters: none
// Returns: Employee
// Method grants request
public Employee grantNextRequest()
{
if (vacationRequests != null)
{
return vacationRequests.dequeue();
}
else
return null;
}
// Method: outputRequests
// Parameters: none
// Returns: Employee
// Method prints requests
public String outputRequests()
{
String o = "";
if (vacationRequests != null)
return o + vacationRequests.toString();
else
return "No vacation requests";
}
// Method: loadEmployees
// Parameters: employeeFIle, requestFile
// Returns: boolean
// Method reads in and loads employees
public boolean loadEmployees(String employeeFile, String requestFile)
{
FileInputStream file, file1;
ObjectInputStream inout = null ;
Scanner in;
Employee ee = null;
Queue q = null;
int emp = 0;
////clear
System.out.print(hourlyList.toString());
employees.clear();
hourlyList.clear();
salaryList.clear();
commissionList.clear();
vacationRequests.clear();
/////ending clear
////employee
try
{
inout = new ObjectInputStream(new FileInputStream(employeeFile));
}
catch (FileNotFoundException fnfe)
{
System.out.println("Error");
}
catch (IOException ioe)
{
System.err.println("etr");
}
if (inout == null)
{
return false;
}
try
{
while(true)
{
try
{
ee = (Employee)inout.readObject();
employees.addItem(ee);
}
catch (NoSuchElementException nsee)
{
break;
}
catch (IOException a)
{
System.err.println("");
return true;
}
}
}
catch (MaximumCapacityException mce)
{
System.out.print("Maximum Capacity Reached");
return true;
}
catch (ClassNotFoundException cnfe)
{
System.out.print("err");
}
//
try
{
file = new FileInputStream(employeeFile);
}
catch (IOException a)
{
System.err.println("err");
return false;
}
//
try
{
if (file != null)
{
file.close();
}
}
catch (IOException IOE)
{
System.err.println("error closing file");
System.exit(1);
}
////queue
try
{
in = new Scanner(new File(requestFile));
}
catch (FileNotFoundException fnfe)
{
System.err.println("err");
return false;
}
while (true)
{
try
{
emp = in.nextInt();
}
catch (NoSuchElementException nsee)
{
break;
}
}
//
try
{
file1 = new FileInputStream(requestFile);
}
catch (IOException ioe)
{
System.out.print("err");
return false;
}
try
{
if (file1 != null)
{
file1.close();
}
}
catch (IOException ioe)
{
System.out.print("err");
System.exit(1);
}
return true;
}
// Method: saveEmployees
// Parameters: employeeFIle, requestFile
// Returns: boolean
// Method saves employees
public boolean saveEmployees(String employeeFile, String requestFile)
{
ObjectOutputStream output;
Formatter put = null;
Queue vacayCopy = new Queue();
vacayCopy = vacationRequests;
////employeefile
try
{
output = new ObjectOutputStream(new FileOutputStream(employeeFile));
}
catch (IOException a)
{
System.out.println("error");
System.exit(1);
return false;
}
for (int x = 0; x < employees.lengthIs(); x++)
{
try
{
output.writeObject(employees.getItem(x));
}
catch (IOException a)
{
System.out.print("Error");
return false;
}
}
try
{
if(output != null)
{
output.close();
}
}
catch (IOException a)
{
System.out.println("error");
System.exit(1);
return false;
}
////requestfile
try
{
put = new Formatter(requestFile);
for (int x = 0; x < vacationRequests.lengthIs(); x++)
{
put.format("%d", vacationRequests.dequeue().getEmployeeNumber());
}
}
catch (FormatterClosedException fce)
{
System.out.println("error");
return false;
}
catch (FileNotFoundException fnfee)
{
System.out.print("err");
}
if (put != null)
{
put.close();
}
return true;
}
// Method: processUpdates
// Parameters: fileName
// Returns: boolean
// Method updates files
public boolean processUpdates(String fileName)
{
int emp = 0;
double requesT = 0.0;
Scanner input;
try
{
input = new Scanner(new File(fileName));
}
catch (FileNotFoundException fnfe)
{
System.out.print("Error, file not found");
System.exit(1);
return false;
}
while (true)
{
try
{
emp = input.nextInt();
requesT = input.nextDouble();
}
catch(NoSuchElementException nsee)
{
break;
}
int temp;
temp = getIndex(emp);
if (employees.getItem(temp) instanceof HourlyEmployee)
{
increaseHours(emp, requesT);
}
if (employees.getItem(emp) instanceof SalaryEmployee)
{
System.out.print("Cannot process update.");
}
if (employees.getItem(emp) instanceof CommissionEmployee)
{
increaseSales(emp,requesT);
}
if (temp == -1)
{
System.out.printf("Cannot process update %d is an invalid employee number.",
emp);
}
}
if (input != null)
{
input.close();
}
return true;
}
}

More Related Content

Similar to I need help with this two methods in java. Here are the guidelines. .pdf

Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
aathiauto
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
aathmaproducts
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
Eelco Visser
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
MILANOP1
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
info114
 

Similar to I need help with this two methods in java. Here are the guidelines. .pdf (20)

JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Pnno
PnnoPnno
Pnno
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
 
Operators
OperatorsOperators
Operators
 
Functions
FunctionsFunctions
Functions
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
A brief introduction to apply functions
A brief introduction to apply functionsA brief introduction to apply functions
A brief introduction to apply functions
 

More from kourystephaniamari30

How would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdfHow would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdf
kourystephaniamari30
 
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdfBMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
kourystephaniamari30
 
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdfBased on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
kourystephaniamari30
 
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
kourystephaniamari30
 

More from kourystephaniamari30 (20)

How would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdfHow would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdf
 
Explain what is meant by a positive relationship between two variabl.pdf
Explain what is meant by a positive relationship between two variabl.pdfExplain what is meant by a positive relationship between two variabl.pdf
Explain what is meant by a positive relationship between two variabl.pdf
 
Ethidium homodimer is responsible for the red color observed. How is.pdf
Ethidium homodimer is responsible for the red color observed. How is.pdfEthidium homodimer is responsible for the red color observed. How is.pdf
Ethidium homodimer is responsible for the red color observed. How is.pdf
 
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdfBMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
 
Describe the specific brain region(s) associated with language, spee.pdf
Describe the specific brain region(s) associated with language, spee.pdfDescribe the specific brain region(s) associated with language, spee.pdf
Describe the specific brain region(s) associated with language, spee.pdf
 
Collected from flower of mountain laurel (Kalmia latifolia) plant. T.pdf
Collected from flower of mountain laurel (Kalmia latifolia) plant.  T.pdfCollected from flower of mountain laurel (Kalmia latifolia) plant.  T.pdf
Collected from flower of mountain laurel (Kalmia latifolia) plant. T.pdf
 
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdfBased on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
 
About 13 of the population is nervous around strangers. If two peop.pdf
About 13 of the population is nervous around strangers. If two peop.pdfAbout 13 of the population is nervous around strangers. If two peop.pdf
About 13 of the population is nervous around strangers. If two peop.pdf
 
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdfAssume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
 
An example would be height in humans Traits have a wide range of valu.pdf
An example would be height in humans Traits have a wide range of valu.pdfAn example would be height in humans Traits have a wide range of valu.pdf
An example would be height in humans Traits have a wide range of valu.pdf
 
A group of BIOL 1114 students were able to measure various metabolic.pdf
A group of BIOL 1114 students were able to measure various metabolic.pdfA group of BIOL 1114 students were able to measure various metabolic.pdf
A group of BIOL 1114 students were able to measure various metabolic.pdf
 
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
 
6. Which of the following has the lowest orbit a. weather satel.pdf
6. Which of the following has the lowest orbit a. weather satel.pdf6. Which of the following has the lowest orbit a. weather satel.pdf
6. Which of the following has the lowest orbit a. weather satel.pdf
 
You can fill the cell background with color or an image A.color b.pdf
You can fill the cell background with color or an image A.color b.pdfYou can fill the cell background with color or an image A.color b.pdf
You can fill the cell background with color or an image A.color b.pdf
 
why do people eating outside rather than home cook SolutionFi.pdf
why do people eating outside rather than home cook SolutionFi.pdfwhy do people eating outside rather than home cook SolutionFi.pdf
why do people eating outside rather than home cook SolutionFi.pdf
 
When a judge sends an innocent person to jail he is making aa. Ty.pdf
When a judge sends an innocent person to jail he is making aa. Ty.pdfWhen a judge sends an innocent person to jail he is making aa. Ty.pdf
When a judge sends an innocent person to jail he is making aa. Ty.pdf
 
Using an inoculating loop, demonstrate how to aseptically remove some.pdf
Using an inoculating loop, demonstrate how to aseptically remove some.pdfUsing an inoculating loop, demonstrate how to aseptically remove some.pdf
Using an inoculating loop, demonstrate how to aseptically remove some.pdf
 
What are the common DSS analysis techniquesSolutionDSS analys.pdf
What are the common DSS analysis techniquesSolutionDSS analys.pdfWhat are the common DSS analysis techniquesSolutionDSS analys.pdf
What are the common DSS analysis techniquesSolutionDSS analys.pdf
 
What are the vulnerabilities in the boot process What can an attack.pdf
What are the vulnerabilities in the boot process What can an attack.pdfWhat are the vulnerabilities in the boot process What can an attack.pdf
What are the vulnerabilities in the boot process What can an attack.pdf
 
True or False Chromosome replication occurs during meiosis and not .pdf
True or False Chromosome replication occurs during meiosis and not .pdfTrue or False Chromosome replication occurs during meiosis and not .pdf
True or False Chromosome replication occurs during meiosis and not .pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 

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)
  • 4. + 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 Solution import java.util.Scanner; import java.io.FileNotFoundException; import java.lang.SecurityException; import java.util.NoSuchElementException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.IOException; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Formatter; import java.util.FormatterClosedException; @SuppressWarnings("unchecked") public class EmployeeManager { private ArrayList employees; private final int employeeMax = 10; private LinkedList hourlyList; private LinkedList salaryList; private LinkedList commissionList; private Queue vacationRequests; public EmployeeManager() { try
  • 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)
  • 16. { if (pos == 0) { hashes[pos] = stringHash(s.substring(pos, pos + length)); } if (pos > 0) { hashes[pos] = 26 * (RabinKarpHashes (s,hashes,pos-1, length) - (charNumericValue (s.charAt(pos-1)) * (int)Math.pow(26,length-1))) + charNumericValue(s.charAt(pos+length-1)); } return hashes[pos]; } // Method: linearSearchRecursive // Parameters: find // Returns: pos // Method does recursivelinear search private int linearSearchRecursive(int[] data, int key, int pos) { if (pos < 0) { return -1; } if (key == data[pos]) { return pos; } return linearSearchRecursive(data, key, pos-1); } // Method: sort // Parameters: none // Returns: pos // Method sorts lists public void sort() {
  • 17. hourlyList.sort(); salaryList.sort(); commissionList.sort(); } // Method: addRequest // Parameters: empNum // Returns: none // Method does adds request for vacation public boolean addRequest(int empNum) { if (empNum >= 10000 && empNum <= 99999) { vacationRequests.enqueue(employees.getItem(getIndex(empNum))); return true; } else return false; } // Method: viewextRequest // Parameters: none // Returns: Employee // Method views next request public Employee viewNextRequest() { Employee emu = null; if (vacationRequests == null) return null; else return emu; } // Method: grantNextRequest // Parameters: none // Returns: Employee // Method grants request
  • 18. public Employee grantNextRequest() { if (vacationRequests != null) { return vacationRequests.dequeue(); } else return null; } // Method: outputRequests // Parameters: none // Returns: Employee // Method prints requests public String outputRequests() { String o = ""; if (vacationRequests != null) return o + vacationRequests.toString(); else return "No vacation requests"; } // Method: loadEmployees // Parameters: employeeFIle, requestFile // Returns: boolean // Method reads in and loads employees public boolean loadEmployees(String employeeFile, String requestFile) { FileInputStream file, file1; ObjectInputStream inout = null ; Scanner in; Employee ee = null; Queue q = null; int emp = 0; ////clear
  • 19. System.out.print(hourlyList.toString()); employees.clear(); hourlyList.clear(); salaryList.clear(); commissionList.clear(); vacationRequests.clear(); /////ending clear ////employee try { inout = new ObjectInputStream(new FileInputStream(employeeFile)); } catch (FileNotFoundException fnfe) { System.out.println("Error"); } catch (IOException ioe) { System.err.println("etr"); } if (inout == null) { return false; } try { while(true) { try { ee = (Employee)inout.readObject(); employees.addItem(ee); } catch (NoSuchElementException nsee) { break;
  • 20. } catch (IOException a) { System.err.println(""); return true; } } } catch (MaximumCapacityException mce) { System.out.print("Maximum Capacity Reached"); return true; } catch (ClassNotFoundException cnfe) { System.out.print("err"); } // try { file = new FileInputStream(employeeFile); } catch (IOException a) { System.err.println("err"); return false; } // try { if (file != null) { file.close(); } } catch (IOException IOE)
  • 21. { System.err.println("error closing file"); System.exit(1); } ////queue try { in = new Scanner(new File(requestFile)); } catch (FileNotFoundException fnfe) { System.err.println("err"); return false; } while (true) { try { emp = in.nextInt(); } catch (NoSuchElementException nsee) { break; } } // try { file1 = new FileInputStream(requestFile); } catch (IOException ioe) { System.out.print("err"); return false; } try
  • 22. { if (file1 != null) { file1.close(); } } catch (IOException ioe) { System.out.print("err"); System.exit(1); } return true; } // Method: saveEmployees // Parameters: employeeFIle, requestFile // Returns: boolean // Method saves employees public boolean saveEmployees(String employeeFile, String requestFile) { ObjectOutputStream output; Formatter put = null; Queue vacayCopy = new Queue(); vacayCopy = vacationRequests; ////employeefile try { output = new ObjectOutputStream(new FileOutputStream(employeeFile)); } catch (IOException a) { System.out.println("error"); System.exit(1); return false; } for (int x = 0; x < employees.lengthIs(); x++)
  • 23. { try { output.writeObject(employees.getItem(x)); } catch (IOException a) { System.out.print("Error"); return false; } } try { if(output != null) { output.close(); } } catch (IOException a) { System.out.println("error"); System.exit(1); return false; } ////requestfile try { put = new Formatter(requestFile); for (int x = 0; x < vacationRequests.lengthIs(); x++) { put.format("%d", vacationRequests.dequeue().getEmployeeNumber()); } } catch (FormatterClosedException fce) { System.out.println("error");
  • 24. return false; } catch (FileNotFoundException fnfee) { System.out.print("err"); } if (put != null) { put.close(); } return true; } // Method: processUpdates // Parameters: fileName // Returns: boolean // Method updates files public boolean processUpdates(String fileName) { int emp = 0; double requesT = 0.0; Scanner input; try { input = new Scanner(new File(fileName)); } catch (FileNotFoundException fnfe) { System.out.print("Error, file not found"); System.exit(1); return false; } while (true) { try {
  • 25. emp = input.nextInt(); requesT = input.nextDouble(); } catch(NoSuchElementException nsee) { break; } int temp; temp = getIndex(emp); if (employees.getItem(temp) instanceof HourlyEmployee) { increaseHours(emp, requesT); } if (employees.getItem(emp) instanceof SalaryEmployee) { System.out.print("Cannot process update."); } if (employees.getItem(emp) instanceof CommissionEmployee) { increaseSales(emp,requesT); } if (temp == -1) { System.out.printf("Cannot process update %d is an invalid employee number.", emp); } } if (input != null) { input.close(); } return true; } }