/********************************************************* * Worker.java * @version 1.0 * creates Worker objects for use in the WorkerTest.java * and WorkDay.java programs for Gadgets and Gizmos * * @author Connor Dixon * 24 February 2014 *********************************************************/ public class Worker { //////////////// // Attributes // //////////////// private String name = ""; private String id = "000-00-0000"; private String level = ""; private int months = 0; private int option = 0; ///////////////////// // Constructor One // /****************************************************** * Creates a new Worker object with a set name, ID, * level, and insurance option. * * @param name - The worker's name. * @param id - The worker's Social Security number. * @param level - The worker's skill level. * @param option - The worker's insurance option. ******************************************************/ public Worker(String name, String id, String level, int option) { this.name = name; if (id.length() == 8 || id.length() == 10) this.id = id; ///////////////// // Error Flags // ///////////////// else this.id = "0000-00-0000"; if (level.equalsIgnoreCase("Apprentice")) this.level = "Apprentice"; else if (level.equalsIgnoreCase("Skilled")) this.level = "Skilled"; else if (level.equalsIgnoreCase("Expert")) this.level = "Expert"; else this.level = "Apprentice"; months = 0; //////////////// // Error Flag // //////////////// if (option < 1 || option > 4) this.option = -1; else this.option = option; } ///////////////////// // Constructor Two // /****************************************************** * Creates a new Worker object with a set name, ID, * and insurance option. * * @param name - The worker's name. * @param id - The worker's Social Security number. * @param option - The worker's insurance option. ******************************************************/ public Worker(String name, String id, int option) { this.name = name; this.id = id; level = "Apprentice"; months = 0; //////////////// // Error Flag // //////////////// if (option < 1 || option > 4) this.option = -1; else this.option = option; } /////////////////////// // Constructor Three // /****************************************************** * Creates a new Worker object with no set parameters. ******************************************************/ public Worker() { this("Anonymous", "000-00-0000", 1); } /////////////// // Set Level // /****************************************************** * Sets the skill level for the worker. * * @param level - The worker's new skill level. ******************************************************/ public void setLevel(String level) { if (level.equalsIgnoreCase("Apprentice")) this.level = "Apprentice"; else if (level.equalsIgnoreCase("Skilled")) this.level = "Skilled"; else if (level.equalsIgnoreCase("Expert")) this.level = "Expert"; else this.level = "Apprentice"; } /////////////// // Get Level // /****************************************************** * Returns the worker's skill level. * * @return level - The worker's skill level. ******************************************************/ public String getLevel() { return level; } //////////////// // Set Months // /****************************************************** * Sets the number of months the worker was at Gadgets * and Gizmos. * * @param months - The worker's months worked. ******************************************************/ public void setMonths(int months) { this.months = Math.abs(months); } //////////////// // get Months // /****************************************************** * Returns the number of months the worker was at * Gadgets and Gizmos. * * @return months - The worker's months worked. ******************************************************/ public int getMonths() { return months; } ////////////// // Set Name // /****************************************************** * Sets the worker's name. * * @param name - The worker's new name. ******************************************************/ public void setName(String name) { this.name = name; } ////////////// // Get Name // /****************************************************** * Returns the worker's name. * * @return name - The worker's name. ******************************************************/ public String getName() { return name; } //////////// // Set ID // /****************************************************** * Sets the Social Security number for the worker. * * @param ssn - The worker's new SSN. ******************************************************/ public void setID(String ssn) { if (ssn.length() != 8 && ssn.length() != 10) id = "000-00-0000"; else id = ssn; } //////////// // Get ID // /****************************************************** * Returns the Social Security number for the worker. * * @return id - The worker's new SSN. ******************************************************/ public String getID() { return id; } //////////////// // Set Option // /****************************************************** * Sets the worker's insurance option. * * @param option - The new insurance option choice. ******************************************************/ public void setOption(int option) { //////////////// // Error Flag // //////////////// if (option < 1 || option > 4) this.option = -1; else this.option = option; } //////////////// // Get Option // /****************************************************** * Returns the worker's insurance option. * * @return option - The insurance option choice. ******************************************************/ public int getOption() { return option; } ////////////// // Promoter // /****************************************************** * Promotes the worker to the next skill level. * * @return Y/N - States if the worker was promoted. ******************************************************/ public boolean promote() { if (level.equals("Apprentice")) { level = "Skilled"; return true; } else if (level.equals("Skilled")) { level = "Expert"; return true; } else return false; } ///////////// // Demoter // /****************************************************** * Demotes the worker to the previous skill level. * * @return Y/N - States if the worker was demoted. ******************************************************/ public boolean demote() { if (level.equals("Skilled")) { level = "Apprentice"; return true; } else if (level.equals("Expert")) { level = "Skilled"; return true; } else return false; } ////////////////////////////// // Calculate Insurance Cost // /****************************************************** * Calculates the weekly insurance cost based on the * worker's insurance option. * * @return cost - The worker's insurance cost. ******************************************************/ public double calcInsuranceCost() { ///////////////////// // Insurance Rates // ///////////////////// final double MEDICAL = 32.50; final double DENTAL = 10.00; final double VISION = 10.00; if (option == 1) return (MEDICAL); else if (option == 2) return (MEDICAL + DENTAL); else if (option == 3) return (MEDICAL + VISION); else if (option == 4) return (MEDICAL + DENTAL + VISION); //////////////// // Error Flag // //////////////// else return -1; } ///////////////////////// // Calculate Gross Pay // /****************************************************** * Calculates the gross pay per week for workers. * * @param hoursWorked - The hours worked per week. ******************************************************/ public double calcGrossPay(double hoursWorked) { double rate = 0.0; if (level.equals("Apprentice")) rate = 17.00; else if (level.equals("Skilled")) rate = 24.00; else if (level.equals("Expert")) rate = 30.00; //////////////// // Error Flag // //////////////// else rate = 0.0; if (hoursWorked <= 40 && hoursWorked >= 0) return (rate * hoursWorked); else if (hoursWorked >= 40) return ((rate * 40) + ((1.5 * rate) * (hoursWorked - 40))); //////////////// // Error Flag // //////////////// else return -1; } ///////////////////// // Calculate Leave // /****************************************************** * Calcualtes the number of leave hours a worker earns * per week. * * @return leave - The leave hours a worker earns. ******************************************************/ public int calcLeave() { if (level.equals("Expert")) if (months >= 0) return 5; //////////////// // Error Flag // //////////////// else return -1; else if (level.equals("Apprentice")) if (months >= 0 && months <= 23) return 1; else if (months >= 24 && months <= 59) return 2; else if (months >= 60) return 3; //////////////// // Error Flag // //////////////// else return -1; else if (level.equals("Skilled")) if (months >= 0 && months <= 23) return 2; else if (months >= 24 && months <= 59) return 3; else if (months >= 60) return 4; //////////////// // Error Flag // //////////////// else return -1; //////////////// // Error Flag // //////////////// else return -1; } /////////// // Print // /****************************************************** * Prints the worker and his/her attributes out. * * @return Worker - The worker and his/her attributes. ******************************************************/ public String toString() { return "Name: " + name + "\nID: " + id + "\nMonths Worked: " + months + "\nSkill Level: " + level + "\nInsurance Option: " + option + "\n"; } }