diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/js/myCompany/company.js | |
add: graphs et rushs
Diffstat (limited to 'graphs/js/myCompany/company.js')
| -rw-r--r-- | graphs/js/myCompany/company.js | 77 |
1 files changed, 77 insertions, 0 deletions
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, +}; |
