Advertisement
chaibs

program-employee

Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. package eleven1;
  2.  
  3. public class Employee {
  4.     public String name;
  5.     public int workID, salary;
  6.  
  7.     public Employee(String n, int wid, int s) {// constructor for employee
  8.         this.name = n;
  9.         if (wid > 1000) {// checking if work id is over 1000
  10.             this.workID = wid;
  11.         }
  12.         this.salary = s;
  13.     }
  14.  
  15.     public String toString() {// output for employee
  16.         return "Employee name " + this.name + " work ID " + this.workID + " salary " + this.salary;
  17.     }
  18.    
  19.     public int calcBonus() {// adding bonus to employee
  20.         return this.salary + 0;
  21.     }
  22.    
  23.     public void updateSalary(int r) {// updating employee salary
  24.         this.salary = r;
  25.     }
  26.  
  27. }
  28. ------------------------------------------------------------------------------------------------------------------------
  29. package eleven1;
  30.  
  31. public class Programmer extends Employee {
  32.  
  33.     public Programmer(String n, int wid, int s) {// constructor for programmer
  34.         super(n, wid, s);
  35.     }
  36.  
  37.     public String toString() {// output for programmer
  38.         return super.toString();
  39.     }
  40.  
  41.     public int calcBonus() {// adding bonus to programmer
  42.         return (int) (super.salary * 1.5);
  43.     }
  44.  
  45. }
  46. ------------------------------------------------------------------------------------------------------------------------
  47. package eleven1;
  48.  
  49. public class Secratry extends Employee {
  50.     public int numOfLetters;
  51.  
  52.     public Secratry(String n, int wid, int s, int nof) {// constructor for secratry
  53.         super(n, wid, s);
  54.         this.numOfLetters = nof;
  55.     }
  56.  
  57.     public String toString() {// output for secratry
  58.         return super.toString();
  59.     }
  60.  
  61.     public int calcBonus() {// adding bonus to secratry
  62.         return super.salary + 500;
  63.     }
  64. }
  65. ------------------------------------------------------------------------------------------------------------------------
  66. package eleven1;
  67.  
  68. public class MainWorker {
  69.  
  70.     public static void main(String[] args) {
  71.         Programmer e1 = new Programmer("Chai", 9193, 7500);// creating programmer
  72.         Secratry e2 = new Secratry("Tal", 5555, 7000, 100);// creating secratry
  73.  
  74.         System.out.println(e1);// output for programmer
  75.         System.out.println(e2);// output for secratry
  76.  
  77.         e1.updateSalary(8000 + e1.calcBonus());// updating salary with bonus for programmer
  78.         e2.updateSalary(7500 + e2.calcBonus());// updating salary with bonus for secratry
  79.  
  80.         System.out.println(e1);// output for programmer
  81.         System.out.println(e2);// output for secratry
  82.     }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement