Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Employee {
- private String name;
- private String employeeID;
- private String hireDate;
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return this.name;
- }
- public void setNumber(String employeeID) {
- this.employeeID = employeeID;
- }
- public String getNumber() {
- return this.employeeID
- .matches("(?i)^[0-9]{3}-[A-M]{1}$") ?
- this.employeeID : "Invalid employee ID! Format must be XXX-L.";
- /* "(?i)" -> case-insensitive, aka ignore case
- "^" -> emphasizes String start
- "[0-9]{3}" -> must match XXX, where X is a digit 0-9
- "-" -> 3 digit code must be followed by a hyphen
- "[A-M]{1}" -> following the hyphen, must be a single letter, A-M
- "$" -> emphasizes String end
- Method uses ternary operator, below is the translation:
- if (employeeID.matches(regex)) {
- return employeeID;
- } else {
- return ""; // some String
- }
- */
- }
- public void setHire(String hireDate) {
- this.hireDate = hireDate;
- }
- public String getHire() {
- return this.hireDate;
- }
- // Default no-args constructor
- public Employee() {
- }
- // Overloaded constructor with 3 parameters
- public Employee(String name, String employeeID, String hireDate) {
- this.name = name;
- this.employeeID = employeeID;
- this.hireDate = hireDate;
- }
- }
- class ProductionWorker extends Employee {
- private int shift;
- private double wage;
- public void setShift(int shift) {
- this.shift = shift;
- }
- public int getShift() {
- return this.shift;
- }
- public void setPayRate(double wage) {
- this.wage = wage;
- }
- public double getPayRate() {
- return this.wage;
- }
- //Default no-args constructor
- public ProductionWorker() {
- }
- // Overloaded constructor with 3 parameters
- public ProductionWorker(String name, String employeeID, String hireDate) {
- // Call constructor from superclass (Employee)
- super(name, employeeID, hireDate);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement