Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- public class Employee {
- protected String _EmpName;
- protected int _EmpNum;
- protected double _Salary;
- /** Employee Constructor
- * @param _EmpName //holds Employee Name
- * @param _EmpNum //hold Employee ID number
- * @param _Salary //hold Beginning Salary
- */
- public Employee(String _EmpName, int _EmpNum, double _Salary) {
- super();
- this._EmpName = _EmpName;
- this._Salary = _Salary;
- if (_EmpNum > 1000) { // If Employee number < 1000 set it to 1000
- this._EmpNum = _EmpNum;
- } else {
- this._EmpNum = 1000;
- }
- }
- //Method that Calculate the Bonus for either Programmer or Secretary
- public double CalcBonus(double PBonusR) {
- if (PBonusR < 10) { // Rate is percent if its less than 100%
- _Salary = this._Salary * PBonusR; //Calculate using the Programmer function
- } else {
- _Salary = this._Salary + Secratry.getSBonusR();
- }
- return this._Salary; // Return calculated Salary with Bonus
- }
- //Method to update bonus for Either a Programmer or a Secretary
- public double UpdateSalary(double NewRate) {
- if (Pragrammer.setPBonusR(NewRate) < 10) { // Set new rate to programmer
- CalcBonus(Pragrammer.setPBonusR(NewRate));
- } else { // its a Secretary bonus
- CalcBonus(Secratry.setSBonusR(NewRate));
- }
- return NewRate;
- }
- //Getter and Setters for All Parameters of the Class
- public String get_EmpName() {
- return _EmpName;
- }
- public void set_EmpName(String _EmpName) {
- this._EmpName = _EmpName;
- }
- public int get_EmpNum() {
- return _EmpNum;
- }
- public void setENum(int _EmpNum) {
- this._EmpNum = _EmpNum;
- }
- public double get_Salary() {
- return _Salary;
- }
- public void set_Salary(double _Salary) {
- this._Salary = _Salary;
- }
- // Method to print Employee before applying any Bonus or Updated bonuses
- @Override
- public String toString() {
- return "Employee [_EmpName=" + _EmpName + ", _EmpNum=" + _EmpNum + ", _Salary=" + _Salary + "]";
- }
- package test;
- public class employeeTester {
- public static void main(String[] args) {
- Pragrammer P1 = new Pragrammer("BeeGee", 900, 6000, 0);
- Secratry S1 = new Secratry("Lola", 1005, 5000, 0, 0);
- System.out.println("============== No Bonus for any================");
- System.out.println(P1.toString());
- System.out.println(S1.toString());
- // after we assign employee bonuses
- P1.CalcBonus(Pragrammer.setPBonusR(2.0));
- System.out.println("==============Bonus 2.0%================");
- System.out.println(P1.toString());
- S1.CalcBonus(Secratry.setSBonusR(1000));
- System.out.println("==============Bonus $1000================");
- System.out.println(S1.toString());
- //after we assign Words per Minute typing speed
- S1.setWordPerMin(80);
- System.out.println("==============Set Typing Speed for Secratry================");
- System.out.println(S1.toString());
- P1.UpdateSalary(3.0);
- System.out.println("==============Updated Rate to 3.0%================");
- System.out.println(P1.toString());
- S1.UpdateSalary(1500);
- System.out.println("==============Updated Bonus $1500.00================");
- System.out.println(S1.toString());
- }
- }
- package test;
- public class Pragrammer extends Employee {
- private static double PBonusR;
- //private static double Programmer Bonus Rate;
- // Getter for Programmer Bonus Rate
- public static double getPBonusR() {
- return PBonusR;
- }
- // Setter for Programmer Bonus Rate
- public static double setPBonusR(double pBonusR) {
- return PBonusR = pBonusR;
- }
- /** Programmer Constructor
- * @param _EmpName //holds Employee Name
- * @param _EmpNum //hold Employee ID number
- * @param _Salary //hold Beginning Salary
- */
- public Pragrammer(String _EmpName, int _EmpNum, double _Salary, double PBonusR) {
- super(_EmpName, _EmpNum, _Salary);
- PBonusR = Pragrammer.PBonusR;
- // set programmer Bonus Parameter to Input%
- }
- // Method to print Programmer with Bonuses if any applied
- @Override
- public String toString() {
- return "Pragrammer [_EmpName=" + _EmpName + ", _EmpNum=" + _EmpNum + ", _Salary=" + _Salary + " Bonus: "
- + PBonusR + "%" + "]";
- }
- }
- package test;
- public class Secratry extends Employee {
- private int WordPerMin; //Parameters that holds Number of typing speed Rate
- private static double SBonusR; //Parameter that hold Bonus Rate
- /** Secretary Constructor
- * @param _EmpName //holds Employee Name
- * @param _EmpNum //hold Employee ID number
- * @param _Salary //hold Beginning Salary
- */
- public Secratry(String _EmpName, int _EmpNum, double _Salary, int WordPerMin, double SBonusR) {
- super(_EmpName, _EmpNum, _Salary);
- this.WordPerMin = WordPerMin;
- Secratry.SBonusR = SBonusR;
- //Secretary set Rate(SBonusR);
- }
- //Getter for Secretary Bonus Rate
- public static double getSBonusR() {
- return SBonusR;
- }
- //Setter for Secretary Bonus Rate
- public static double setSBonusR(double sBonusR) {
- return SBonusR = sBonusR;
- }
- //Getter for Secretary Words Per Minutes Rate
- public int getWordPerMin() {
- return WordPerMin;
- }
- //Setter for Secretary Words Per Minutes Rate
- public void setWordPerMin(int wordPerMin) {
- WordPerMin = wordPerMin;
- }
- // Method to print Secretary with Bonuses and WPM typing speed if any applied
- @Override
- public String toString() {
- return "Secratry [WordPerMin=" + WordPerMin + ", _EmpName=" + _EmpName + ", _EmpNum=" + _EmpNum + ", _Salary="
- + _Salary + " Typing W.P.M " + "Rate =" + getWordPerMin() + " Bonus of Set Amount of $" + SBonusR + "]";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement