Question

I need help with this one method in java. Here are the guidelines. Only public Employee[]...

I need help with this one method in java. Here are the guidelines. Only public Employee[] findAllBySubstring(String find).

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class EmployeeManager
{
private Employee[] employees;
private final int employeeMax = 100;
private int currentEmployees;
public EmployeeManager()
{

     employees[] = new Employee[employeeMax];

     currentEmployees = 0;
}

public void addEmployee(int eType, String fn, String ln, char m, char g, int empNum, boolean ft, double a)
{
    double sales = 0.0, hoursWorked = 0.0;
    switch (eType)
    {
       case 1: employees[currentEmployees] = new HourlyEmployee(fn, ln, m, g, empNum, ft, a, hoursWorked);
                currentEmployees++;
                break;

        case 2: employees[currentEmployees] = new SalaryEmployee(fn, ln, m, g, empNum, ft, a);
                currentEmployees++;
                break;

        case 3: employees[currentEmployees] = new CommissionEmployee(fn, ln, m, g, empNum, ft, a, sales);
                currentEmployees++;
                break;
    }
}
//Add Employee
            case 2:
                String fn, ln;
                char mi, g, f;
                boolean ft = true;
                do
                {
                    System.out.println("\n1. Hourly");
                    System.out.println("2. Salary");
                    System.out.println("3. Commission");
                    System.out.print("Enter Choice: ");
                    subInput1 = in.nextInt();

                    if(subInput1 < 1 || subInput1 > 3)
                    {
                        System.out.println("Invalid Choice! Choose again.");
                    }
                }while(subInput1 < 1 || subInput1 > 3);

                System.out.print("Enter Last Name: ");
                ln = in.next();
                System.out.print("Enter First Name: ");
                fn = in.next();
                System.out.print("Enter Middle Initial: ");
                mi = in.next().charAt(0);
                System.out.print("Enter Gender: ");
                g = in.next().charAt(0);
                System.out.print("Enter Employee Number: ");
                en = in.nextInt();
                System.out.print("Full Time? (y/n): ");
                f = in.next().charAt(0);
                if(f == 'n' || f == 'N')
                {
                    ft = false;
                }

                if(subInput1 == 1)
                {
                    System.out.print("Enter wage: ");
                }
                else if(subInput1 == 2)
                {
                    System.out.print("Enter salary: ");
                }
                else
                {
                    System.out.print("Enter rate: ");
                }
                amount = in.nextDouble();

                em.addEmployee(subInput1, fn, ln , mi, g, en, ft, amount);
                em.removeRedundancies();
                break;

/**** HourlyEmployee is a subclass of superclass Employee. Here's my code . *******/

public class HourlyEmployee extends Employee
{
private double wage;
private double hoursWorked;

public HourlyEmployee(String fn, String ln, char m, char g, int empNum, boolean ft, double w, double h)
{
    super (fn, ln, m, g, empNum, ft);
    wage = w;
    hoursWorked = h;
    hoursWorked = 0.0;
}

@Override
public String toString()
{
    return this.getEmployeeNumber() + "\n" + lastName + ", " + firstName + middleInitial + "\n" + "Gender: "
     + this.getGender() + "\n" + "Status: " + fulltime + "\n" + "Wage: " + wage + "\n" + "Hours Worked: " + hoursWorked + "\n";
}

@Override
public double calculateWeeklyPay()
{
    if (hoursWorked > 40)
    {
        wage = wage * 2;
    }

    return wage * hoursWorked;
}

@Override
public void annualRaise()
{
    wage = (wage * .05) + wage;
}

@Override
public double holidayBonus()
{
    return wage * 40;
}

@Override
public void resetWeek()
{
    hoursWorked = 0.0;
}

public double plusHoursWorked(double amount, double h)
{
    while (amount <= 0)
    {
        System.out.println("Invalid value entered, please try again");
    }

    return amount + h;
}

}
public abstract class Employee
{
protected String firstName;
protected String lastName;
protected char middleInitial;
protected boolean fulltime;
private char gender;
private int employeeNum;

public Employee (String fn, String ln, char m, char g, int empNum, boolean ft)
{
    firstName = fn;
    lastName = ln;
    middleInitial = m;
    gender = g;
    employeeNum = empNum;
    fulltime = ft;
}

public int getEmployeeNumber()
{
    return employeeNum;
}

public void setEmployeeNumber(int empNum)
{
    while (empNum <= 10000 && empNum >= 99999)
    {
        System.out.print ("Invalid input, please try again: ");
    }

    if (empNum >= 10000 && empNum <= 99999)
    {
        employeeNum = empNum;
    }
}

public String getFirstName()
{
    return firstName;
}

public String getLastName()
{
    return lastName;
}

public char checkGender(char g)
{
    if (g != 'M' || g != 'F')
    {
        g = 'F';
    }
    return g;
}
public char getGender()
{
    return gender;
}

@Override
public boolean equals(Object e2)
{
    if (this.employeeNum == ((Employee)e2).employeeNum)
    {
        return true;
    }
    else
    {
        return false;
    }
}

@Override
public String toString()
{
    return employeeNum + "\n" + lastName + ", " + firstName + "\n" + "Gender:" + gender + "\n" + "Status:" + fulltime + "\n";
}

public abstract double calculateWeeklyPay();

public abstract void annualRaise();

public abstract double holidayBonus();

public abstract void resetWeek();
}
Add a comment
Know the answer?
Add Answer to:
I need help with this one method in java. Here are the guidelines. Only public Employee[]...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I was wondering if I could get some help with a Java Program that I am...

    I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...

  • JAVA Submit:    HashSet.java    with the following methods added: HashSet.java // Implements a set of...

    JAVA Submit:    HashSet.java    with the following methods added: HashSet.java // Implements a set of objects using a hash table. // The hash table uses separate chaining to resolve collisions. // Original from buildingjavaprograms.com supplements public class HashSet<E> { private static final double MAX_LOAD_FACTOR = 0.75; private HashEntry<E>[] elementData; private int size; // Constructs an empty set. @SuppressWarnings("unchecked") public HashSet() { elementData = new HashEntry[10]; size = 0; } // ADD METHODS HERE for exercise solutions: // Adds the...

  • JAVA (advanced data structures) write a completed program using HashIntSet and HashMain include the method in the main...

    JAVA (advanced data structures) write a completed program using HashIntSet and HashMain include the method in the main if possible. those are just the sample HashIntSet and HashMain (don't have to be the same but follow the Q requirement. thanks HashIntSet.java public class HashIntSet { private static final double MAX_LOAD_FACTOR = 0.75; private HashEntry[] elementData; private int size; // Constructs an empty set. public HashIntSet() { elementData = new HashEntry[10]; size = 0; } // Adds the given element to...

  • Write a method in the HashIntSet class called addAll that accepts another hash set as a...

    Write a method in the HashIntSet class called addAll that accepts another hash set as a parameter and adds all of the elements from the other set into the current set. For example, if the set stores [-5, 1, 2, 3] and the method is passed [2, 3, 6, 44, 79], your set would store [-5, 1, 2, 3, 6, 44, 79]. Write a method in the HashIntSet class called containsAll that accepts another hash set as a parameter and...

  • help with java OOP, here is the started code: package P2; public class Farm {   ...

    help with java OOP, here is the started code: package P2; public class Farm {    private double availableFood;    private Animal[] animals;    public Farm() {        setAvailableFood(1000);        animals = new Animal[4];        animals[0] = new Chicken();        animals[1] = new Cow();        animals[2] = new Llama();        animals[3] = new Llama();    }    public void makeNoise(){           // all animals make their sound (Moo, Cluck, etc)        for(Animal...

  • Complete an Array-Based implementation of the ADT List including a main method and show that the...

    Complete an Array-Based implementation of the ADT List including a main method and show that the ADT List works. Draw a class diagram of the ADT List __________________________________________ public interface IntegerListInterface{ public boolean isEmpty(); //Determines whether a list is empty. //Precondition: None. //Postcondition: Returns true if the list is empty, //otherwise returns false. //Throws: None. public int size(); // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of items in this IntegerList. //Throws: None....

  • Java - I need help creating a method that removes a node at the specific index...

    Java - I need help creating a method that removes a node at the specific index position. The * first node is index 0. public boolean delAt(int index) { src code 2 different classes ******************************************** public class Node { private String data; private Node next; public Node(String data, Node next) { this.data = data; this.next = next; } public Node() { } public String getData() { return data; } public void setData(String data) { this.data = data; } public void...

  • JAVA: How do I output all the data included for each employee? I can only get...

    JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...

  • HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private...

    HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private int empNumber;    private double hoursWorked;    private double payRate;       private static int hospitalEmployeeCount = 0;    //-----------------------------------------------------------------    // Sets up this hospital employee with default information.    //-----------------------------------------------------------------    public HospitalEmployee()    { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0;               hospitalEmployeeCount++;    }       //overloaded constructor.    public HospitalEmployee(String eName,...

  • In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate...

    In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a monthly salary for every year in service. 4) Print the calculated pension for all employees. ************** I added the interface and I implemented the interface with Employee class but, I don't know how can i call the method in main class ************ import java.io.*; public class ManagerTest { public static void main(String[] args) { InputStreamReader...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT