diff options
Diffstat (limited to 'graphs/js/myCompany')
| -rw-r--r-- | graphs/js/myCompany/boss.js | 30 | ||||
| -rw-r--r-- | graphs/js/myCompany/company.js | 77 | ||||
| -rw-r--r-- | graphs/js/myCompany/employee.js | 21 |
3 files changed, 128 insertions, 0 deletions
diff --git a/graphs/js/myCompany/boss.js b/graphs/js/myCompany/boss.js new file mode 100644 index 0000000..eadf09c --- /dev/null +++ b/graphs/js/myCompany/boss.js @@ -0,0 +1,30 @@ +const { Employee } = require("./employee"); + +class Boss extends Employee { + constructor(name, accreditationLevel) { + super(name); + this.accreditationLevel = accreditationLevel; + } + getAccreditation() { + return this.accreditationLevel; + } + fire(target) { + if (!(target instanceof Employee)) { + console.log("I cannot fire that!"); + return false; + } else if ( + !(target instanceof Boss) || + target.getAccreditation() < this.accreditationLevel + ) { + console.log(target.getName() + " you are fired!"); + return true; + } else { + console.log("I cannot fire someone superior to me!"); + return false; + } + } +} + +module.exports = { + Boss, +}; diff --git a/graphs/js/myCompany/company.js b/graphs/js/myCompany/company.js new file mode 100644 index 0000000..fd800e7 --- /dev/null +++ b/graphs/js/myCompany/company.js @@ -0,0 +1,77 @@ +const { Boss } = require("./boss"); +const { Employee } = require("./employee"); + +class Company { + constructor(name) { + this.name = name; + this.employees = new Array(); + } + getName() { + return this.name; + } + getEmployees() { + return this.employees; + } + getNumberOfEmployees() { + return this.employees.filter((e) => e instanceof Employee).length; + } + getNumberOfBosses() { + return this.employees.filter((e) => e instanceof Boss).length; + } + addEmployee(target) { + if (!(target instanceof Employee)) { + return; + } + + this.employees.push(target); + } + promoteEmployee(targetIndex) { + if (this.employees[targetIndex] instanceof Boss) { + this.employees[targetIndex].accreditationLevel++; + console.log( + "Boss " + + this.employees[targetIndex].getName() + + " is promoted, his level of accreditation is now " + + this.employees[targetIndex].getAccreditation(), + ); + } else { + this.employees.splice( + targetIndex, + 1, + new Boss(this.employees[targetIndex].getName(), 1), + ); + console.log( + "Employee " + + this.employees[targetIndex].getName() + + " is promoted to boss post", + ); + } + } + fireEmployee(bossIndex, targetIndex) { + if (this.employees[bossIndex].fire(this.employees[targetIndex])) { + if (this.employees[targetIndex] instanceof Boss) { + console.log( + "Boss " + + this.employees[targetIndex].getName() + + " is no longer in " + + this.name + + " company", + ); + } else { + console.log( + "Employee " + + this.employees[targetIndex].getName() + + " is no longer in " + + this.name + + " company", + ); + } + + this.employees.splice(targetIndex, 1); + } + } +} + +module.exports = { + Company, +}; diff --git a/graphs/js/myCompany/employee.js b/graphs/js/myCompany/employee.js new file mode 100644 index 0000000..5489dd7 --- /dev/null +++ b/graphs/js/myCompany/employee.js @@ -0,0 +1,21 @@ +class Employee { + constructor(name) { + this.name = name; + } + getName() { + return this.name; + } + fire(target) { + if (target instanceof Employee) { + console.log("I am an employee, I cannot fire someone!"); + } else { + console.log("I cannot fire that!"); + } + + return false; + } +} + +module.exports = { + Employee, +}; |
