RexyBadDog

Lesson012_28_08_19_Task2 CLASSES

Aug 30th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. // this Class is for java homework name: Lesson012_28_08_19_Task2
  2.  
  3. public class Employee {
  4.     protected String name;
  5.     protected double salary;
  6.     private static int sysId = 1000;
  7.  
  8.     // builders:
  9.     public Employee(String name, int sysId, double salary) {
  10.         System.out.println("Employee() full constructor");
  11.         this.name = name;
  12.         this.sysId = sysId;
  13.         this.salary = salary;
  14.     }
  15.     public Employee() {
  16.         // random salary between 6,000 and 9,000.
  17.         this("employee No" + (sysId-1000), sysId, ((int)(Math.random()*6)*500) + 6000);
  18.         System.out.println("Employee() empty constructor");
  19.         sysId += 1; // increase count of employees
  20.     }
  21.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  22.     public double calcBonus(double bonus) {
  23.         return bonus;
  24.     }
  25.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  26.     public void updateSalary (double bonus) {
  27.          this.salary = salary + calcBonus(bonus);
  28.     }
  29.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  30.     @Override
  31.     public String toString() {
  32.         return "Employee{" +
  33.                 "name='" + name + '\'' +
  34.                 ", sysId=" + + sysId +
  35.                 ", salary=" + salary +
  36.                 '}';
  37.     }
  38. }
  39. // ####################################################################################################
  40. // this Class is for java homework name: Lesson012_28_08_19_Task2
  41.  
  42. public class Programmer extends Employee {
  43.  
  44.     // builders:
  45.     public Programmer (String name, int sysId, int salary) {
  46.         super(name, sysId, salary);
  47.     }
  48.     public Programmer () {
  49.         super();
  50.     }
  51.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  52.     public double calcBonus() {
  53.         return salary * 0.5f;
  54.     }
  55.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  56.     @Override
  57.     public String toString() {
  58.         return "Programmer type " + super.toString();
  59.     }
  60. }
  61. // ####################################################################################################
  62. // this Class is for java homework name: Lesson012_28_08_19_Task2
  63.  
  64. public class Secretary extends Employee {
  65.     private int wordsPerMinute;
  66.  
  67.     // builders:
  68.     public Secretary (String name, int sysId, int salary, int wordsPerMinute) {
  69.         super(name, sysId, salary);
  70.         this.wordsPerMinute = wordsPerMinute;
  71.     }
  72.     public Secretary () {
  73.         super();
  74.         this.wordsPerMinute = (int)(Math.random()*30);
  75.     }
  76.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  77.     public double calcBonus() {
  78.         return calcBonus(500);
  79.     }
  80.     // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  81.     @Override
  82.     public String toString() {
  83.         return "Secretary type " + super.toString() +
  84.                 "{wordsPerMinute=" + wordsPerMinute +
  85.                         '}';
  86.     }
  87. }
Add Comment
Please, Sign In to add comment