Advertisement
eranseg

Employee

Aug 28th, 2019
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. //------------------ Employee - Base class ------------------
  2.  
  3. public class Employee {
  4.  
  5.     protected String name;
  6.     private static int idGenerator = 1000;
  7.     protected double salary;
  8.     protected int employID;
  9.  
  10.     public Employee(String name, double salary) {
  11.         this.name = name;
  12.         this.salary = salary;
  13.         this.employID = idGenerator;
  14.         idGenerator++;
  15.     }
  16.  
  17.     public double getSalary() {
  18.         return salary;
  19.     }
  20.  
  21.     @Override
  22.     public String toString() {
  23.         return "Employee name is: " + this.name + ", his ID is: " + this.employID + ", and his salary is: " + this.salary + ".";
  24.     }
  25.  
  26.     public double calcBonus() {
  27.         return 0;
  28.     }
  29.  
  30.     public void updateSalary(double newSalary) {
  31.         this.salary = newSalary;
  32.     }
  33. }
  34.  
  35. //-------------------- Programmer ---------------------------------
  36.  
  37. public class Programmer extends Employee{
  38.  
  39.     public Programmer(String name, double salary) {
  40.         super(name, salary);
  41.     }
  42.  
  43.     @Override
  44.     public double calcBonus() {
  45.         return super.getSalary()*1.5;
  46.     }
  47. }
  48.  
  49. //------------------------ Secretary -----------------------------
  50.  
  51. public class Secretary extends Employee{
  52.  
  53.     private int wordsTypedPerMin;
  54.  
  55.     public Secretary(String name, double salary, int wordsTypedPerMin) {
  56.         super(name, salary);
  57.         this.wordsTypedPerMin = wordsTypedPerMin;
  58.     }
  59.  
  60.     @Override
  61.     public double calcBonus() {
  62.         return super.getSalary()+500;
  63.     }
  64.  
  65.     @Override
  66.     public String toString() {
  67.         return super.toString() + " In Addition, the secretary types: " + this.wordsTypedPerMin + " words per minute.";
  68.     }
  69. }
  70.  
  71. //------------------------------- Main class -------------------------
  72.  
  73. public class EmpMain {
  74.     public static void main(String[] args) {
  75.         Programmer pr = new Programmer("Benny", 1200);
  76.         Secretary sec = new Secretary("Gilad", 1000, 74);
  77.         System.out.println(pr.toString());
  78.         System.out.println(sec.toString());
  79.         pr.updateSalary(pr.calcBonus());
  80.         sec.updateSalary(sec.calcBonus());
  81.         System.out.println(pr.toString());
  82.         System.out.println(sec.toString());
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement