Advertisement
Guest User

employee

a guest
Dec 11th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. class Employee {
  2.         private String name;
  3.         private String employeeID;
  4.         private String hireDate;
  5.  
  6.         public void setName(String name) {
  7.                 this.name = name;
  8.         }
  9.         public String getName() {
  10.                 return this.name;
  11.         }
  12.         public void setNumber(String employeeID) {
  13.                 this.employeeID = employeeID;
  14.         }
  15.         public String getNumber() {
  16.                 return this.employeeID
  17.                         .matches("(?i)^[0-9]{3}-[A-M]{1}$") ?
  18.                                 this.employeeID : "Invalid employee ID! Format must be XXX-L.";
  19.                 /* "(?i)" -> case-insensitive, aka ignore case
  20.                    "^" -> emphasizes String start
  21.                    "[0-9]{3}" -> must match XXX, where X is a digit 0-9
  22.                    "-" -> 3 digit code must be followed by a hyphen
  23.                    "[A-M]{1}" -> following the hyphen, must be a single letter, A-M
  24.                    "$" -> emphasizes String end
  25.                    
  26.                    Method uses ternary operator, below is the translation:
  27.                    
  28.                    if (employeeID.matches(regex)) {
  29.                         return employeeID;
  30.                    } else {
  31.                         return ""; // some String
  32.                    }
  33.                */
  34.         }
  35.         public void setHire(String hireDate) {
  36.                 this.hireDate = hireDate;
  37.         }
  38.         public String getHire() {
  39.                 return this.hireDate;
  40.         }  
  41.        
  42.         // Default no-args constructor
  43.         public Employee() {
  44.  
  45.         }
  46.         // Overloaded constructor with 3 parameters
  47.         public Employee(String name, String employeeID, String hireDate) {
  48.                 this.name = name;
  49.                 this.employeeID = employeeID;
  50.                 this.hireDate = hireDate;
  51.         }
  52.  
  53. }
  54. class ProductionWorker extends Employee {
  55.         private int shift;
  56.         private double wage;
  57.  
  58.         public void setShift(int shift) {
  59.                 this.shift = shift;
  60.         }
  61.         public int getShift() {
  62.                 return this.shift;
  63.         }
  64.         public void setPayRate(double wage) {
  65.                 this.wage = wage;
  66.         }
  67.         public double getPayRate() {
  68.                 return this.wage;
  69.         }
  70.            
  71.         //Default no-args constructor
  72.         public ProductionWorker() {
  73.                
  74.         }
  75.         // Overloaded constructor with 3 parameters
  76.         public ProductionWorker(String name, String employeeID, String hireDate) {
  77.                 // Call constructor from superclass (Employee)
  78.                 super(name, employeeID, hireDate);
  79.         }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement